process termination can be divided into normal process termination and process exception termination.
- The normal termination of a process is as follows:
- The main function returns
- Call the Exit function
- Call the _exit or _exit function
- The last thread returns from the startup code
- The last thread calls Pthread_exit
- There are several situations where the process terminates abnormally:
- Call the Abort function
- Process received signal termination
- The last thread responds to a cancellation request
========================================================the difference between the Exit function and the _exit/_exit function is:The exit function is not immediately entered into the kernel state, but it is preceded by a number of termination handlers (functions registered with the Atexit function), as well as forcing the flush of all user buffers and so on. The _exit and _exit functions are immediately entered into the kernel state to perform kernel processing, and the user buffer is not processed. The _exit or _exit function is also encapsulated in the Exit function. using the return keyword in the main function is identical to calling the Exit function. ========================================================the function of the Atexit function is to register the function, which will be executed when calling the Exit function or using the return keyword in the main function. The order of execution and the order of the calls is reversed. function Prototypes:function Parameters:
- Function: Functions pointer
return Value:
- return 0 upon successful invocation
- Return non 0 if call fails
Process Environment Details (ii)---process termination and atexit functions