abort

Description

Aborts the current process and returns an error code.

#include <process.h> #include <stdlib.h> Required only for function declarations; use either PROCESS.H or STDLIB.H  

void abort( void );

Remarks

The abort function prints the message

abnormal program termination

to stderr, then calls raise(SIGABRT). The action taken in response to the SIGABRT signal depends on what action has been defined for that signal in a prior call to the signal function. The default SIGABRT action is for the calling process to terminate with exit code 3, returning control to the parent process or operating system.

In Windows, the abort function does not call raise(SIGABRT). Instead, it terminates the process with an “Abnormal Program Termination” pop-up message. In Windows multithread libraries, the abort function does not call raise(SIGABRT). Instead, it terminates the process with exit code 3.

The abort function does not flush stream buffers or do atexit/_onexit processing.

Return Value

The abort function does not return control to the caller. Rather, it terminates the process and, by default, returns an exit code of 3 to the parent process.

Compatibility

Standards:ANSI, UNIX

16-Bit:DOS, QWIN, WIN, WIN DLL

32-Bit:DOS32X

See Also

_exec functions, exit, _exit, raise, signal, _spawn functions

Example

/* ABORT.C: This tries to open a file and aborts if the attempt fails. */

#include <stdio.h>

#include <stdlib.h>

void main( void )

{

FILE *stream;

if( (stream = fopen( "NOSUCHF.ILE", "r" )) == NULL )

{

perror( "Couldn't open file" );

abort();

}

else

fclose( stream );

}

Output

Couldn't open file: No such file or directory

abnormal program termination