1EXIT(3) Linux Programmer's Manual EXIT(3)
2
3
4
6 exit - cause normal process termination
7
9 #include <stdlib.h>
10
11 void exit(int status);
12
14 The exit() function causes normal process termination and the value of
15 status & 0377 is returned to the parent (see wait(2)).
16
17 All functions registered with atexit(3) and on_exit(3) are called, in
18 the reverse order of their registration. (It is possible for one of
19 these functions to use atexit(3) or on_exit(3) to register an addi‐
20 tional function to be executed during exit processing; the new regis‐
21 tration is added to the front of the list of functions that remain to
22 be called.) If one of these functions does not return (e.g., it calls
23 _exit(2), or kills itself with a signal), then none of the remaining
24 functions is called, and further exit processing (in particular, flush‐
25 ing of stdio(3) streams) is abandoned. If a function has been regis‐
26 tered multiple times using atexit(3) or on_exit(3), then it is called
27 as many times as it was registered.
28
29 All open stdio(3) streams are flushed and closed. Files created by
30 tmpfile(3) are removed.
31
32 The C standard specifies two constants, EXIT_SUCCESS and EXIT_FAILURE,
33 that may be passed to exit() to indicate successful or unsuccessful
34 termination, respectively.
35
37 The exit() function does not return.
38
40 SVr4, 4.3BSD, POSIX.1-2001, C89, C99.
41
43 It is undefined what happens if one of the functions registered using
44 atexit(3) and on_exit(3) calls either exit() or longjmp(3).
45
46 The use of EXIT_SUCCESS and EXIT_FAILURE is slightly more portable (to
47 non-Unix environments) than the use of 0 and some nonzero value like 1
48 or -1. In particular, VMS uses a different convention.
49
50 BSD has attempted to standardize exit codes; see the file <sysexits.h>.
51
52 After exit(), the exit status must be transmitted to the parent
53 process. There are three cases. If the parent has set SA_NOCLDWAIT,
54 or has set the SIGCHLD handler to SIG_IGN, the status is discarded. If
55 the parent was waiting on the child it is notified of the exit status.
56 In both cases the exiting process dies immediately. If the parent has
57 not indicated that it is not interested in the exit status, but is not
58 waiting, the exiting process turns into a "zombie" process (which is
59 nothing but a container for the single byte representing the exit sta‐
60 tus) so that the parent can learn the exit status when it later calls
61 one of the wait(2) functions.
62
63 If the implementation supports the SIGCHLD signal, this signal is sent
64 to the parent. If the parent has set SA_NOCLDWAIT, it is undefined
65 whether a SIGCHLD signal is sent.
66
67 If the process is a session leader and its controlling terminal is the
68 controlling terminal of the session, then each process in the fore‐
69 ground process group of this controlling terminal is sent a SIGHUP sig‐
70 nal, and the terminal is disassociated from this session, allowing it
71 to be acquired by a new controlling process.
72
73 If the exit of the process causes a process group to become orphaned,
74 and if any member of the newly orphaned process group is stopped, then
75 a SIGHUP signal followed by a SIGCONT signal will be sent to each
76 process in this process group. See setpgid(2) for an explanation of
77 orphaned process groups.
78
80 _exit(2), setpgid(2), wait(2), atexit(3), on_exit(3), tmpfile(3)
81
83 This page is part of release 3.25 of the Linux man-pages project. A
84 description of the project, and information about reporting bugs, can
85 be found at http://www.kernel.org/doc/man-pages/.
86
87
88
89Linux 2009-09-20 EXIT(3)