]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man3/exit.3
3ab26841fef05c0eb6a7adbd604f1c8d97fde45a
[thirdparty/man-pages.git] / 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 2001-11-17 "" "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 \fBexit()\fP function causes normal process termination and the
34 the value of \fIstatus & 0377\fP is returned to the parent
35 (see
36 .BR wait (2)).
37 All process termination functions registered with
38 \fBatexit()\fP and \fBon_exit()\fP
39 are called, in the reverse order of their registration,
40 and all open streams are flushed and closed.
41 Files created by \fItmpfile()\fP are removed.
42 .LP
43 The C standard specifies two constants
44 \fIEXIT_SUCCESS\fP and \fIEXIT_FAILURE\fP
45 that may be passed to \fBexit()\fP to indicate successful or unsuccessful
46 termination, respectively.
47 .SH "RETURN VALUE"
48 The \fBexit()\fP function does not return.
49 .SH "CONFORMING TO"
50 SVID 3, POSIX, BSD 4.3, ISO 9899 (``ANSI C'')
51 .SH NOTES
52 During exit processing, a process termination function may
53 register additional process termination
54 functions with \fBatexit()\fP and \fBon_exit()\fP.
55 These functions are added to the front of the list of
56 process termination functions that remain to be called.
57 .LP
58 It is undefined what happens if one of the process termination
59 functions calls either \fBexit()\fP or \fBlongjmp()\fP.
60 .LP
61 The use of EXIT_SUCCESS and EXIT_FAILURE is slightly more portable
62 (to non-Unix environments) than that of 0 and some nonzero value
63 like 1 or \-1. In particular, VMS uses a different convention.
64 .LP
65 BSD has attempted to standardize exit codes - see the file
66 .IR <sysexits.h> .
67 .LP
68 After \fBexit()\fP, the exit status must be transmitted to the
69 parent process. There are three cases. If the parent has set
70 SA_NOCLDWAIT, or has set the SIGCHLD handler to SIG_IGN, the
71 status is discarded. If the parent was waiting on the child
72 it is notified of the exit status. In both cases the exiting
73 process dies immediately. If the parent has not indicated that
74 it is not interested in the exit status, but is not waiting,
75 the exiting process turns into a "zombie" process
76 (which is nothing but a container for the single byte representing
77 the exit status) so that the parent can learn the exit status when
78 it later calls one of the \fIwait()\fP functions.
79 .LP
80 If the implementation supports the SIGCHLD signal, this signal
81 is sent to the parent. If the parent has set SA_NOCLDWAIT,
82 it is undefined whether a SIGCHLD signal is sent.
83 .LP
84 If the process is a session leader and its controlling terminal
85 the controlling terminal of the session, then each process in
86 the foreground process group of this controlling terminal
87 is sent a SIGHUP signal, and the terminal is disassociated
88 from this session, allowing it to be acquired by a new controlling
89 process.
90 .LP
91 If the exit of the process causes a process group to become orphaned,
92 and if any member of the newly orphaned process group is stopped,
93 then a SIGHUP signal followed by a SIGCONT signal will be
94 sent to each process in this process group.
95 .SH "SEE ALSO"
96 .BR _exit (2),
97 .BR wait (2),
98 .BR atexit (3),
99 .BR on_exit (3),
100 .BR tmpfile (3)