The _exit
function is the primitive used for process termination by exit
. It is declared in the header file `unistd.h'.
_exit
function is the primitive for causing a process to terminate with status status. Calling this function does not execute cleanup functions registered with atexit
or on_exit
. When a process terminates for any reason---either by an explicit termination call, or termination as a result of a signal---the following things happen:
All open file descriptors in the process are closed. See Low-Level I/O. Note that streams are not flushed automatically when the process terminates; See I/O on Streams.
The low-order 8 bits of the return status code are saved to be reported back to the parent process via wait
or waitpid
; see Process Completion.
Any child processes of the process being terminated are assigned a new parent process. (On most systems, including GNU, this is the init
process, with process ID 1.)
A SIGCHLD
signal is sent to the parent process.
If the process is a session leader that has a controlling terminal, then a SIGHUP
signal is sent to each process in the foreground job, and the controlling terminal is disassociated from that session. See Job Control.
If termination of a process causes a process group to become orphaned, and any member of that process group is stopped, then a SIGHUP
signal and a SIGCONT
signal are sent to each process in the group. See Job Control.