1 .\" Copyright (C) 2001 Andries Brouwer <aeb@cwi.nl>.
3 .\" %%%LICENSE_START(VERBATIM)
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date. The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein. The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
25 .\" FIXME . There are a lot of other process termination actions that
26 .\" could be listed on this page. See, for example, the list in the
27 .\" POSIX exit(3p) page.
29 .TH EXIT 3 2021-03-22 "Linux" "Linux Programmer's Manual"
31 exit \- cause normal process termination
34 .B #include <stdlib.h>
36 .BI "noreturn void exit(int " status );
41 function causes normal process termination and the least significant byte of
43 (i.e., \fIstatus & 0xFF\fP) is returned to the parent (see
46 All functions registered with
50 are called, in the reverse order of their registration.
51 (It is possible for one of these functions to use
55 to register an additional
56 function to be executed during exit processing;
57 the new registration is added to the front of the list of functions
58 that remain to be called.)
59 If one of these functions does not return
62 or kills itself with a signal),
63 then none of the remaining functions is called,
64 and further exit processing (in particular, flushing of
66 streams) is abandoned.
67 If a function has been registered multiple times using
71 then it is called as many times as it was registered.
75 streams are flushed and closed.
80 The C standard specifies two constants,
81 \fBEXIT_SUCCESS\fP and \fBEXIT_FAILURE\fP,
84 to indicate successful or unsuccessful
85 termination, respectively.
89 function does not return.
91 For an explanation of the terms used in this section, see
99 Interface Attribute Value
102 T} Thread safety MT-Unsafe race:exit
110 function uses a global variable that is not protected,
111 so it is not thread-safe.
113 POSIX.1-2001, POSIX.1-2008, C89, C99, SVr4, 4.3BSD.
115 The behavior is undefined if one of the functions registered using
125 removes registrations created using
134 is slightly more portable
135 (to non-UNIX environments) than the use of 0 and some nonzero value
137 In particular, VMS uses a different convention.
139 BSD has attempted to standardize exit codes
140 (which some C libraries such as the GNU C library have also adopted);
146 the exit status must be transmitted to the
148 There are three cases:
150 If the parent has set
156 the status is discarded and the child dies immediately.
158 If the parent was waiting on the child,
159 it is notified of the exit status and the child dies immediately.
162 the child becomes a "zombie" process:
163 most of the process resources are recycled,
164 but a slot containing minimal information about the child process
165 (termination status, resource usage statistics) is retained in process table.
166 This allows the parent to subsequently use
168 (or similar) to learn the termination status of the child;
169 at that point the zombie process slot is released.
171 If the implementation supports the
174 is sent to the parent.
175 If the parent has set
177 it is undefined whether a
181 .SS Signals sent to other processes
182 If the exiting process is a session leader and its controlling terminal
183 is the controlling terminal of the session, then each process in
184 the foreground process group of this controlling terminal
187 signal, and the terminal is disassociated
188 from this session, allowing it to be acquired by a new controlling
191 If the exit of the process causes a process group to become orphaned,
192 and if any member of the newly orphaned process group is stopped,
198 sent to each process in this process group.
201 for an explanation of orphaned process groups.
203 Except in the above cases,
204 where the signalled processes may be children of the terminating process,
205 termination of a process does
207 in general cause a signal to be sent to children of that process.
208 However, a process can use the
211 operation to arrange that it receives a signal if its parent terminates.
214 .BR get_robust_list (2),