Atexit function name: atexit
Header file: # include <stdlib. h>
Function: registers the termination function (that is, the function called after the main execution ends)
Usage: int atexit (void (* func) (void ));
Note: according to iso c, a process can register up to 32 functions, which will be automatically called by exit. The function type registered by atexit () should be void functions that do not accept any parameters. The order in which exit calls these registration functions is the opposite of the order in which they are registered. If the same function is registered multiple times, it will also be called multiple times.
Program example:
# Include <stdio. h>
# Include <stdlib. h>
Void exit_fn1 (void)
{
Printf ("exit function #1 called \ n ");
}
Void exit_fn2 (void)
{
Printf ("exit function #2 called \ n ");
}
Int main (void)
{
/* Post exit function #1 */
Atexit (exit_fn1 );
/* Post exit function #2 */
Atexit (exit_fn2 );
Return 0;
}
Output:
Exit function #2 called
Exit function #1 called
Process Termination method:
There are eight ways to terminate the process, the first five of which are normal termination, they are
1: return from main
2: Call exit
3: Call _ exit or _ exit
4: The last thread returns from its startup routine
5: The last thread calls pthread_exit.
There are three types of exceptional termination:
6: call abort
7. receive a signal and terminate
8: The last thread responds to the cancellation request.
# Include <stdlib. h?
Void exit (INT status );
Void _ exit (INT status );
# Include <unistd. h>
Void _ exit (Status );
None of the call _ exit and _ exit will call the termination program.
No exception will be terminated.