1 .\" Copyright (C) 2001 Andries Brouwer <aeb@cwi.nl>.
3 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
5 .\" FIXME . There are a lot of other process termination actions that
6 .\" could be listed on this page. See, for example, the list in the
7 .\" POSIX exit(3p) page.
9 .TH EXIT 3 2021-03-22 "Linux man-pages (unreleased)" "Linux Programmer's Manual"
11 exit \- cause normal process termination
14 .RI ( libc ", " \-lc )
17 .B #include <stdlib.h>
19 .BI "noreturn void exit(int " status );
24 function causes normal process termination and the least significant byte of
26 (i.e., \fIstatus & 0xFF\fP) is returned to the parent (see
29 All functions registered with
33 are called, in the reverse order of their registration.
34 (It is possible for one of these functions to use
38 to register an additional
39 function to be executed during exit processing;
40 the new registration is added to the front of the list of functions
41 that remain to be called.)
42 If one of these functions does not return
45 or kills itself with a signal),
46 then none of the remaining functions is called,
47 and further exit processing (in particular, flushing of
49 streams) is abandoned.
50 If a function has been registered multiple times using
54 then it is called as many times as it was registered.
58 streams are flushed and closed.
63 The C standard specifies two constants,
64 \fBEXIT_SUCCESS\fP and \fBEXIT_FAILURE\fP,
67 to indicate successful or unsuccessful
68 termination, respectively.
72 function does not return.
74 For an explanation of the terms used in this section, see
82 Interface Attribute Value
85 T} Thread safety MT-Unsafe race:exit
93 function uses a global variable that is not protected,
94 so it is not thread-safe.
96 POSIX.1-2001, POSIX.1-2008, C89, C99, SVr4, 4.3BSD.
98 The behavior is undefined if one of the functions registered using
108 removes registrations created using
117 is slightly more portable
118 (to non-UNIX environments) than the use of 0 and some nonzero value
120 In particular, VMS uses a different convention.
122 BSD has attempted to standardize exit codes
123 (which some C libraries such as the GNU C library have also adopted);
129 the exit status must be transmitted to the
131 There are three cases:
133 If the parent has set
139 the status is discarded and the child dies immediately.
141 If the parent was waiting on the child,
142 it is notified of the exit status and the child dies immediately.
145 the child becomes a "zombie" process:
146 most of the process resources are recycled,
147 but a slot containing minimal information about the child process
148 (termination status, resource usage statistics) is retained in process table.
149 This allows the parent to subsequently use
151 (or similar) to learn the termination status of the child;
152 at that point the zombie process slot is released.
154 If the implementation supports the
157 is sent to the parent.
158 If the parent has set
160 it is undefined whether a
164 .SS Signals sent to other processes
165 If the exiting process is a session leader and its controlling terminal
166 is the controlling terminal of the session, then each process in
167 the foreground process group of this controlling terminal
170 signal, and the terminal is disassociated
171 from this session, allowing it to be acquired by a new controlling
174 If the exit of the process causes a process group to become orphaned,
175 and if any member of the newly orphaned process group is stopped,
181 sent to each process in this process group.
184 for an explanation of orphaned process groups.
186 Except in the above cases,
187 where the signalled processes may be children of the terminating process,
188 termination of a process does
190 in general cause a signal to be sent to children of that process.
191 However, a process can use the
194 operation to arrange that it receives a signal if its parent terminates.
197 .BR get_robust_list (2),