gtpc2m0a | C/C++ Language Support User's Guide |
This function stops a program.
Format
#include <stdlib.h> void abort(void);
This function causes an abnormal program termination and returns control to the host environment. No dumps are issued for entry control block (ECB) states that are not valid such as having a hold on a file address, having a general tape open or assigned, or having issued a PAUSC macro to place the system in a uniprocessor environment (these conditions are cleared by exit processing).
If the abort function is called and the user has a handler for SIGABRT, then SIGABRT is raised; however, SIGABRT is raised again with the default handler if the user's handler returns, even if it has set another SIGABRT handler. The code path only passes through a user handler once, even if the handler is reset. Abnormal termination also occurs if SIGABRT is ignored.
As part of termination, the system attempts to complete normal exit processing, including calling atexit functions, flushing and closing open files, and removing files created by tmpfile. If the attempt at normal termination causes a system error, the process is immediately forced to exit.
The exit status that is returned to a parent process depends on how the SIGABRT handler causes the process to exit.
TARGET(TPF) restriction |
---|
TARGET(TPF) does not support the raise function; therefore, the TARGET(TPF) version of abort does not raise SIGABRT. The status returned to a parent process is undefined. |
Normal Return
The abort function does not return to its caller and causes abnormal termination of the calling process.
Error Return
Not applicable.
Programming Considerations
Examples
The following example tests for successful opening of the file myfile. If an error occurs, an error message is printed and the program ends with a call to the abort function.
#include <stdio.h> #include <stdlib.h> int main(void) { FILE *stream; if ((stream = fopen("myfile.dat", "r")) == NULL) { printf("Could not open data file\n"); abort(); printf("Should not see this message\n"); } }
Related Information