OSDN Git Service

LDP: Update original to LDP v3.50.
[linuxjm/jm.git] / manual / LDP_man-pages / 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 .TH EXIT 3  2013-02-14 "Linux" "Linux Programmer's Manual"
26 .SH NAME
27 exit \- cause normal process termination
28 .SH SYNOPSIS
29 .nf
30 .B #include <stdlib.h>
31 .sp
32 .BI "void exit(int " status );
33 .fi
34 .SH DESCRIPTION
35 The
36 .BR exit ()
37 function causes normal process termination and the
38 value of \fIstatus & 0377\fP is returned to the parent
39 (see
40 .BR wait (2)).
41 .LP
42 All functions registered with
43 .BR atexit (3)
44 and
45 .BR on_exit (3)
46 are called, in the reverse order of their registration.
47 (It is possible for one of these functions to use
48 .BR atexit (3)
49 or
50 .BR on_exit (3)
51 to register an additional
52 function to be executed during exit processing;
53 the new registration is added to the front of the list of functions
54 that remain to be called.)
55 If one of these functions does not return
56 (e.g., it calls
57 .BR _exit (2),
58 or kills itself with a signal),
59 then none of the remaining functions is called,
60 and further exit processing (in particular, flushing of
61 .BR stdio (3)
62 streams) is abandoned.
63 If a function has been registered multiple times using
64 .BR atexit (3)
65 or
66 .BR on_exit (3),
67 then it is called as many times as it was registered.
68 .LP
69 All open
70 .BR stdio (3)
71 streams are flushed and closed.
72 Files created by
73 .BR tmpfile (3)
74 are removed.
75 .LP
76 The C standard specifies two constants,
77 \fBEXIT_SUCCESS\fP and \fBEXIT_FAILURE\fP,
78 that may be passed to
79 .BR exit ()
80 to indicate successful or unsuccessful
81 termination, respectively.
82 .SH RETURN VALUE
83 The
84 .BR exit ()
85 function does not return.
86 .SH CONFORMING TO
87 SVr4, 4.3BSD, POSIX.1-2001, C89, C99.
88 .SH NOTES
89 .LP
90 It is undefined what happens if one of the
91 functions registered using
92 .BR atexit (3)
93 and
94 .BR on_exit (3)
95 calls either
96 .BR exit ()
97 or
98 .BR longjmp (3).
99 Note that a call to
100 .BR execve (2)
101 removes registrations created using
102 .BR atexit (3)
103 and
104 .BR on_exit (3).
105 .LP
106 The use of
107 .B EXIT_SUCCESS
108 and
109 .B EXIT_FAILURE
110 is slightly more portable
111 (to non-UNIX environments) than the use of 0 and some nonzero value
112 like 1 or \-1.
113 In particular, VMS uses a different convention.
114 .LP
115 BSD has attempted to standardize exit codes; see the file
116 .IR <sysexits.h> .
117 .LP
118 After
119 .BR exit (),
120 the exit status must be transmitted to the
121 parent process.
122 There are three cases.
123 If the parent has set
124 .BR SA_NOCLDWAIT ,
125 or has set the
126 .B SIGCHLD
127 handler to
128 .BR SIG_IGN ,
129 the status is discarded.
130 If the parent was waiting on the child
131 it is notified of the exit status.
132 In both cases the exiting
133 process dies immediately.
134 If the parent has not indicated that
135 it is not interested in the exit status, but is not waiting,
136 the exiting process turns into a "zombie" process
137 (which is nothing but a container for the single byte representing
138 the exit status) so that the parent can learn the exit status when
139 it later calls one of the
140 .BR wait (2)
141 functions.
142 .LP
143 If the implementation supports the
144 .B SIGCHLD
145 signal, this signal
146 is sent to the parent.
147 If the parent has set
148 .BR SA_NOCLDWAIT ,
149 it is undefined whether a
150 .B SIGCHLD
151 signal is sent.
152 .LP
153 If the process is a session leader and its controlling terminal
154 is the controlling terminal of the session, then each process in
155 the foreground process group of this controlling terminal
156 is sent a
157 .B SIGHUP
158 signal, and the terminal is disassociated
159 from this session, allowing it to be acquired by a new controlling
160 process.
161 .LP
162 If the exit of the process causes a process group to become orphaned,
163 and if any member of the newly orphaned process group is stopped,
164 then a
165 .B SIGHUP
166 signal followed by a
167 .B SIGCONT
168 signal will be
169 sent to each process in this process group.
170 See
171 .BR setpgid (2)
172 for an explanation of orphaned process groups.
173 .SH SEE ALSO
174 .BR _exit (2),
175 .BR setpgid (2),
176 .BR wait (2),
177 .BR atexit (3),
178 .BR on_exit (3),
179 .BR tmpfile (3)