OSDN Git Service

(split) LDP_man-pages: update original to v3.34.
[linuxjm/LDP_man-pages.git] / original / man3 / exit.3
1 .\" Copyright (C) 2001 Andries Brouwer <aeb@cwi.nl>.
2 .\"
3 .\" Permission is granted to make and distribute verbatim copies of this
4 .\" manual provided the copyright notice and this permission notice are
5 .\" preserved on all copies.
6 .\"
7 .\" Permission is granted to copy and distribute modified versions of this
8 .\" manual under the conditions for verbatim copying, provided that the
9 .\" entire resulting derived work is distributed under the terms of a
10 .\" permission notice identical to this one.
11 .\"
12 .\" Since the Linux kernel and libraries are constantly changing, this
13 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
14 .\" responsibility for errors or omissions, or for damages resulting from
15 .\" the use of the information contained herein.  The author(s) may not
16 .\" have taken the same level of care in the production of this manual,
17 .\" which is licensed free of charge, as they might when working
18 .\" professionally.
19 .\"
20 .\" Formatted or processed versions of this manual, if unaccompanied by
21 .\" the source, must acknowledge the copyright and authors of this work.
22 .\"
23 .TH EXIT 3  2009-09-20 "Linux" "Linux Programmer's Manual"
24 .SH NAME
25 exit \- cause normal process termination
26 .SH SYNOPSIS
27 .nf
28 .B #include <stdlib.h>
29 .sp
30 .BI "void exit(int " status );
31 .fi
32 .SH DESCRIPTION
33 The
34 .BR exit ()
35 function causes normal process termination and the
36 value of \fIstatus & 0377\fP is returned to the parent
37 (see
38 .BR wait (2)).
39 .LP
40 All functions registered with
41 .BR atexit (3)
42 and
43 .BR on_exit (3)
44 are called, in the reverse order of their registration.
45 (It is possible for one of these functions to use
46 .BR atexit (3)
47 or
48 .BR on_exit (3)
49 to register an additional
50 function to be executed during exit processing;
51 the new registration is added to the front of the list of functions
52 that remain to be called.)
53 If one of these functions does not return
54 (e.g., it calls
55 .BR _exit (2),
56 or kills itself with a signal),
57 then none of the remaining functions is called,
58 and further exit processing (in particular, flushing of
59 .BR stdio (3)
60 streams) is abandoned.
61 If a function has been registered multiple times using
62 .BR atexit (3)
63 or
64 .BR on_exit (3),
65 then it is called as many times as it was registered.
66 .LP
67 All open
68 .BR stdio (3)
69 streams are flushed and closed.
70 Files created by
71 .BR tmpfile (3)
72 are removed.
73 .LP
74 The C standard specifies two constants,
75 \fBEXIT_SUCCESS\fP and \fBEXIT_FAILURE\fP,
76 that may be passed to
77 .BR exit ()
78 to indicate successful or unsuccessful
79 termination, respectively.
80 .SH "RETURN VALUE"
81 The
82 .BR exit ()
83 function does not return.
84 .SH "CONFORMING TO"
85 SVr4, 4.3BSD, POSIX.1-2001, C89, C99.
86 .SH NOTES
87 .LP
88 It is undefined what happens if one of the
89 functions registered using
90 .BR atexit (3)
91 and
92 .BR on_exit (3)
93 calls either
94 .BR exit ()
95 or
96 .BR longjmp (3).
97 .LP
98 The use of
99 .B EXIT_SUCCESS
100 and
101 .B EXIT_FAILURE
102 is slightly more portable
103 (to non-UNIX environments) than the use of 0 and some nonzero value
104 like 1 or \-1.
105 In particular, VMS uses a different convention.
106 .LP
107 BSD has attempted to standardize exit codes; see the file
108 .IR <sysexits.h> .
109 .LP
110 After
111 .BR exit (),
112 the exit status must be transmitted to the
113 parent process.
114 There are three cases.
115 If the parent has set
116 .BR SA_NOCLDWAIT ,
117 or has set the
118 .B SIGCHLD
119 handler to
120 .BR SIG_IGN ,
121 the status is discarded.
122 If the parent was waiting on the child
123 it is notified of the exit status.
124 In both cases the exiting
125 process dies immediately.
126 If the parent has not indicated that
127 it is not interested in the exit status, but is not waiting,
128 the exiting process turns into a "zombie" process
129 (which is nothing but a container for the single byte representing
130 the exit status) so that the parent can learn the exit status when
131 it later calls one of the
132 .BR wait (2)
133 functions.
134 .LP
135 If the implementation supports the
136 .B SIGCHLD
137 signal, this signal
138 is sent to the parent.
139 If the parent has set
140 .BR SA_NOCLDWAIT ,
141 it is undefined whether a
142 .B SIGCHLD
143 signal is sent.
144 .LP
145 If the process is a session leader and its controlling terminal
146 is the controlling terminal of the session, then each process in
147 the foreground process group of this controlling terminal
148 is sent a
149 .B SIGHUP
150 signal, and the terminal is disassociated
151 from this session, allowing it to be acquired by a new controlling
152 process.
153 .LP
154 If the exit of the process causes a process group to become orphaned,
155 and if any member of the newly orphaned process group is stopped,
156 then a
157 .B SIGHUP
158 signal followed by a
159 .B SIGCONT
160 signal will be
161 sent to each process in this process group.
162 See
163 .BR setpgid (2)
164 for an explanation of orphaned process groups.
165 .SH "SEE ALSO"
166 .BR _exit (2),
167 .BR setpgid (2),
168 .BR wait (2),
169 .BR atexit (3),
170 .BR on_exit (3),
171 .BR tmpfile (3)