1 .\" Copyright (C) 2001 Andries Brouwer <aeb@cwi.nl>.
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.
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
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
20 .\" Formatted or processed versions of this manual, if unaccompanied by
21 .\" the source, must acknowledge the copyright and authors of this work.
23 .TH EXIT 3 2001-11-17 "" "Linux Programmer's Manual"
25 exit \- cause normal program termination
28 .B #include <stdlib.h>
30 .BI "void exit(int " status );
33 The \fBexit()\fP function causes normal program termination and the
34 the value of \fIstatus & 0377\fP is returned to the parent
37 All functions registered with \fBatexit()\fP and \fBon_exit()\fP
38 are called in the reverse order of their registration,
39 and all open streams are flushed and closed.
40 Files created by \fItmpfile()\fP are removed.
42 The C standard specifies two defines \fIEXIT_SUCCESS\fP and \fIEXIT_FAILURE\fP
43 that may be passed to \fBexit()\fP to indicate successful or unsuccessful
44 termination, respectively.
46 The \fBexit()\fP function does not return.
48 SVID 3, POSIX, BSD 4.3, ISO 9899 (``ANSI C'')
50 During the exit processing, it is possible to register additional
51 functions with \fBatexit()\fP and \fBon_exit()\fP.
52 Always the last-registered function is removed from the chain
53 of registered functions, and invoked.
54 It is undefined what happens if during this processing
55 either \fBexit()\fP or \fBlongjmp()\fP is called.
57 The use of EXIT_SUCCESS and EXIT_FAILURE is slightly more portable
58 (to non-Unix environments) than that of 0 and some nonzero value
59 like 1 or \-1. In particular, VMS uses a different convention.
61 BSD has attempted to standardize exit codes - see the file
64 After \fBexit()\fP, the exit status must be transmitted to the
65 parent process. There are three cases. If the parent has set
66 SA_NOCLDWAIT, or has set the SIGCHLD handler to SIG_IGN, the
67 status is discarded. If the parent was waiting on the child
68 it is notified of the exit status. In both cases the exiting
69 process dies immediately. If the parent has not indicated that
70 it is not interested in the exit status, but is not waiting,
71 the exiting process turns into a "zombie" process
72 (which is nothing but a container for the single byte representing
73 the exit status) so that the parent can learn the exit status when
74 it later calls one of the \fIwait()\fP functions.
76 If the implementation supports the SIGCHLD signal, this signal
77 is sent to the parent. If the parent has set SA_NOCLDWAIT,
78 it is undefined whether a SIGCHLD signal is sent.
80 If the process is a session leader and its controlling terminal
81 the controlling terminal of the session, then each process in
82 the foreground process group of this controlling terminal
83 is sent a SIGHUP signal, and the terminal is disassociated
84 from this session, allowing it to be acquired by a new controlling
87 If the exit of the process causes a process group to become orphaned,
88 and if any member of the newly-orphaned process group is stopped,
89 then a SIGHUP signal followed by a SIGCONT signal will be
90 sent to each process in this process group.