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