abort: Terminate program abnormally
This function stops a program.
Last updated
Changed in 2024 (information only; no code change).
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.
If the abort function is called, the program ends immediately. The atexit function, and destructors for static and local (automatic) objects, are not called.
The exit status that is returned to a parent process depends on how the SIGABRT handler causes the process to exit.
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
- Following a call to the abort function, no return is made to the operational program.
- If the abort function is called within a commit scope, processing ends as if a rollback was issued.
Examples
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");
}
}