2 ms·
man 3 exit The exit() function causes normal process termination and the least significant byte of status (i.e., status & 0xFF) is returne
by kccqzy 5y ago
man 3 exit
The exit() function causes normal process termination and the
least significant byte of status (i.e., status & 0xFF) is
returned to the parent (see wait(2)).
All functions registered with atexit(3) and on_exit(3) are
called, in the reverse order of their registration. (It is
possible for one of these functions to use atexit(3) or
on_exit(3) to register an additional function to be executed
during exit processing; the new registration is added to the
front of the list of functions that remain to be called.) If one
of these functions does not return (e.g., it calls _exit(2), or
kills itself with a signal), then none of the remaining functions
is called, and further exit processing (in particular, flushing
of stdio(3) streams) is abandoned. If a function has been
registered multiple times using atexit(3) or on_exit(3), then it
is called as many times as it was registered.
All open stdio(3) streams are flushed and closed. Files created
by tmpfile(3) are removed.
These all happen inside userspace. The kernel doesn't necessarily know it's exiting. It's _exit() that tells the kernel the process is exiting. The kernel then does some more processing like closing file descriptors.
man 2 _exit
_exit() terminates the calling process "immediately". Any open
file descriptors belonging to the process are closed. Any
children of the process are inherited by init(1) (or by the
nearest "subreaper" process as defined through the use of the
prctl(2) PR_SET_CHILD_SUBREAPER operation). The process's parent
is sent a SIGCHLD signal.
The value status & 0xFF is returned to the parent process as the
process's exit status, and can be collected by the parent using
one of the wait(2) family of calls.