OSDN Git Service

LDP: Update original to LDP v3.68
[linuxjm/LDP_man-pages.git] / original / man3 / exit.3
1 .\" Copyright (C) 2001 Andries Brouwer <aeb@cwi.nl>.
2 .\"
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.
7 .\"
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.
12 .\"
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
19 .\" professionally.
20 .\"
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
23 .\" %%%LICENSE_END
24 .\"
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.
28 .\"
29 .TH EXIT 3  2014-03-25 "Linux" "Linux Programmer's Manual"
30 .SH NAME
31 exit \- cause normal process termination
32 .SH SYNOPSIS
33 .nf
34 .B #include <stdlib.h>
35 .sp
36 .BI "void exit(int " status );
37 .fi
38 .SH DESCRIPTION
39 The
40 .BR exit ()
41 function causes normal process termination and the
42 value of \fIstatus & 0377\fP is returned to the parent
43 (see
44 .BR wait (2)).
45 .LP
46 All functions registered with
47 .BR atexit (3)
48 and
49 .BR on_exit (3)
50 are called, in the reverse order of their registration.
51 (It is possible for one of these functions to use
52 .BR atexit (3)
53 or
54 .BR on_exit (3)
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
60 (e.g., it calls
61 .BR _exit (2),
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
65 .BR stdio (3)
66 streams) is abandoned.
67 If a function has been registered multiple times using
68 .BR atexit (3)
69 or
70 .BR on_exit (3),
71 then it is called as many times as it was registered.
72 .LP
73 All open
74 .BR stdio (3)
75 streams are flushed and closed.
76 Files created by
77 .BR tmpfile (3)
78 are removed.
79 .LP
80 The C standard specifies two constants,
81 \fBEXIT_SUCCESS\fP and \fBEXIT_FAILURE\fP,
82 that may be passed to
83 .BR exit ()
84 to indicate successful or unsuccessful
85 termination, respectively.
86 .SH RETURN VALUE
87 The
88 .BR exit ()
89 function does not return.
90 .SH ATTRIBUTES
91 .SS Multithreading (see pthreads(7))
92 The
93 .BR exit ()
94 function uses a global variable that is not protected,
95 so it is not thread-safe.
96 .SH CONFORMING TO
97 SVr4, 4.3BSD, POSIX.1-2001, C89, C99.
98 .SH NOTES
99 .LP
100 It is undefined what happens if one of the
101 functions registered using
102 .BR atexit (3)
103 and
104 .BR on_exit (3)
105 calls either
106 .BR exit ()
107 or
108 .BR longjmp (3).
109 Note that a call to
110 .BR execve (2)
111 removes registrations created using
112 .BR atexit (3)
113 and
114 .BR on_exit (3).
115 .LP
116 The use of
117 .B EXIT_SUCCESS
118 and
119 .B EXIT_FAILURE
120 is slightly more portable
121 (to non-UNIX environments) than the use of 0 and some nonzero value
122 like 1 or \-1.
123 In particular, VMS uses a different convention.
124 .LP
125 BSD has attempted to standardize exit codes; see the file
126 .IR <sysexits.h> .
127 .LP
128 After
129 .BR exit (),
130 the exit status must be transmitted to the
131 parent process.
132 There are three cases.
133 If the parent has set
134 .BR SA_NOCLDWAIT ,
135 or has set the
136 .B SIGCHLD
137 handler to
138 .BR SIG_IGN ,
139 the status is discarded.
140 If the parent was waiting on the child,
141 it is notified of the exit status.
142 In both cases the exiting
143 process dies immediately.
144 If the parent has not indicated that
145 it is not interested in the exit status, but is not waiting,
146 the exiting process turns into a "zombie" process
147 (which is nothing but a container for the single byte representing
148 the exit status) so that the parent can learn the exit status when
149 it later calls one of the
150 .BR wait (2)
151 functions.
152 .LP
153 If the implementation supports the
154 .B SIGCHLD
155 signal, this signal
156 is sent to the parent.
157 If the parent has set
158 .BR SA_NOCLDWAIT ,
159 it is undefined whether a
160 .B SIGCHLD
161 signal is sent.
162 .LP
163 If the process is a session leader and its controlling terminal
164 is the controlling terminal of the session, then each process in
165 the foreground process group of this controlling terminal
166 is sent a
167 .B SIGHUP
168 signal, and the terminal is disassociated
169 from this session, allowing it to be acquired by a new controlling
170 process.
171 .LP
172 If the exit of the process causes a process group to become orphaned,
173 and if any member of the newly orphaned process group is stopped,
174 then a
175 .B SIGHUP
176 signal followed by a
177 .B SIGCONT
178 signal will be
179 sent to each process in this process group.
180 See
181 .BR setpgid (2)
182 for an explanation of orphaned process groups.
183 .SH SEE ALSO
184 .BR _exit (2),
185 .BR setpgid (2),
186 .BR wait (2),
187 .BR atexit (3),
188 .BR on_exit (3),
189 .BR tmpfile (3)
190 .SH COLOPHON
191 This page is part of release 3.68 of the Linux
192 .I man-pages
193 project.
194 A description of the project,
195 information about reporting bugs,
196 and the latest version of this page,
197 can be found at
198 \%http://www.kernel.org/doc/man\-pages/.