EXIT(3) Linux Programmer's Manual EXIT(3)
NAME
exit(3,n,1 builtins) - cause normal program termination
SYNOPSIS
#include <stdlib.h>
void exit(3,n,1 builtins)(int status);
DESCRIPTION
The exit(3,n,1 builtins)() function causes normal program termination and the the value
of status & 0377 is returned to the parent (see wait(2)). All func-
tions registered with atexit() and on_exit() are called in(1,8) the reverse
order of their registration, and all open(2,3,n) streams are flushed and
closed. Files created by tmpfile() are removed.
The C standard specifies two defines EXIT_SUCCESS and EXIT_FAILURE that
may be passed to exit(3,n,1 builtins)() to indicate successful or unsuccessful termina-
tion, respectively.
RETURN VALUE
The exit(3,n,1 builtins)() function does not return.
CONFORMING TO
SVID 3, POSIX, BSD 4.3, ISO 9899 (``ANSI C'')
NOTES
During the exit(3,n,1 builtins) processing, it is possible to register additional func-
tions with atexit() and on_exit(). Always the last-registered function
is removed from the chain of registered functions, and invoked. It is
undefined what happens if(3,n) during this processing either exit(3,n,1 builtins)() or
longjmp() is called.
The use of EXIT_SUCCESS and EXIT_FAILURE is slightly more portable (to
non-Unix environments) than that of 0 and some nonzero value like 1 or
-1. In particular, VMS uses a different convention.
BSD has attempted to standardize exit(3,n,1 builtins) codes - see the file(1,n) <sysex-
its.h>.
After exit(3,n,1 builtins)(), the exit(3,n,1 builtins) status must be transmitted to the parent
process. There are three cases. If the parent has set(7,n,1 builtins) SA_NOCLDWAIT, or
has set(7,n,1 builtins) the SIGCHLD handler to SIG_IGN, the status is discarded. If the
parent was waiting on the child it is notified of the exit(3,n,1 builtins) status. In
both cases the exiting process dies immediately. If the parent has not
indicated that it is not interested in(1,8) the exit(3,n,1 builtins) status, but is not
waiting, the exiting process turns into a "zombie" process (which is
nothing but a container for the single byte representing the exit(3,n,1 builtins) sta-
tus) so that the parent can learn the exit(3,n,1 builtins) status when it later calls
one of the wait() functions.
If the implementation supports the SIGCHLD signal(2,7), this signal(2,7) is sent
to the parent. If the parent has set(7,n,1 builtins) SA_NOCLDWAIT, it is undefined
whether a SIGCHLD signal(2,7) is sent.
If the process is a session leader and its controlling terminal the
controlling terminal of the session, then each process in(1,8) the fore-
ground process group of this controlling terminal is sent a SIGHUP sig-
nal(2,7), and the terminal is disassociated from this session, allowing it
to be acquired by a new controlling process.
If the exit(3,n,1 builtins) of the process causes a process group to become orphaned,
and if(3,n) any member of the newly-orphaned process group is stopped, then
a SIGHUP signal(2,7) followed by a SIGCONT signal(2,7) will be sent to each
process in(1,8) this process group.
SEE ALSO
_exit(2), wait(2), atexit(3), on_exit(3), tmpfile(3)
2001-11-17 EXIT(3)