Section: Linux Programmer's Manual (3)
exit - cause normal process termination
void exit(int status);
function causes normal process termination and the
value of status & 0377
is returned to the parent
All functions registered with
are called, in the reverse order of their registration.
(It is possible for one of these functions to use
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
or kills itself with a signal),
then none of the remaining functions is called,
and further exit processing (in particular, flushing of
streams) is abandoned.
If a function has been registered multiple times using
then it is called as many times as it was registered.
streams are flushed and closed.
Files created by
The C standard specifies two constants,
EXIT_SUCCESS and EXIT_FAILURE,
that may be passed to
to indicate successful or unsuccessful
function does not return.
For an explanation of the terms used in this section, see
||Thread safety||MT-Unsafe race:exit|
function uses a global variable that is not protected,
so it is not thread-safe.
POSIX.1-2001, POSIX.1-2008, C89, C99, SVr4, 4.3BSD.
The behavior is undefined if one of the functions registered using
Note that a call to
removes registrations created using
The use of
is slightly more portable
(to non-UNIX environments) than the use of 0 and some nonzero value
like 1 or -1.
In particular, VMS uses a different convention.
BSD has attempted to standardize exit codes
(which some C libraries such as the GNU C library have also adopted);
see the file
the exit status must be transmitted to the
There are three cases:
If the parent has set
or has set the
the status is discarded and the child dies immediately.
If the parent was waiting on the child,
it is notified of the exit status and the child dies immediately.
the child becomes a "zombie" process:
most of the process resources are recycled,
but a slot containing minimal information about the child process
(termination status, resource usage statistics) is retained in process table.
This allows the parent to subsequently use
(or similar) to learn the termination status of the child;
at that point the zombie process slot is released.
If the implementation supports the
signal, this signal
is sent to the parent.
If the parent has set
it is undefined whether a
signal is sent.
Signals sent to other processes
If the exiting process is a session leader and its controlling terminal
is the controlling terminal of the session, then each process in
the foreground process group of this controlling terminal
is sent a
signal, and the terminal is disassociated
from this session, allowing it to be acquired by a new controlling
If the exit of the process causes a process group to become orphaned,
and if any member of the newly orphaned process group is stopped,
signal followed by a
signal will be
sent to each process in this process group.
for an explanation of orphaned process groups.
Except in the above cases,
where the signalled processes may be children of the terminating process,
termination of a process does
in general cause a signal to be sent to children of that process.
However, a process can use the
operation to arrange that it receives a signal if its parent terminates.
This page is part of release 5.02 of the Linux
A description of the project,
information about reporting bugs,
and the latest version of this page,
can be found at