1EXIT(3)                    Linux Programmer's Manual                   EXIT(3)
2
3
4

NAME

6       exit - cause normal process termination
7

SYNOPSIS

9       #include <stdlib.h>
10
11       void exit(int status);
12

DESCRIPTION

14       The  exit() function causes normal process termination and the value of
15       status & 0377 is returned to the parent (see wait(2)).
16
17       All functions registered with atexit() and on_exit() are called, in the
18       reverse  order of their registration.  (It is possible for one of these
19       functions to use atexit() or on_exit() to register an additional  func‐
20       tion  to  be  executed  during exit processing; the new registration is
21       added to the front of the list of functions that remain to be called.)
22
23       All open streams are flushed and closed.  Files  created  by  tmpfile()
24       are removed.
25
26       The  C standard specifies two constants, EXIT_SUCCESS and EXIT_FAILURE,
27       that may be passed to exit() to  indicate  successful  or  unsuccessful
28       termination, respectively.
29

RETURN VALUE

31       The exit() function does not return.
32

CONFORMING TO

34       SVr4, 4.3BSD, POSIX.1-2001, C89, C99.
35

NOTES

37       It  is  undefined what happens if one of the functions registered using
38       atexit() and on_exit() calls either exit() or longjmp().
39
40       The use of EXIT_SUCCESS and EXIT_FAILURE is slightly more portable  (to
41       non-Unix environments) than that of 0 and some non-zero value like 1 or
42       -1. In particular, VMS uses a different convention.
43
44       BSD has attempted to standardize exit codes; see the file <sysexits.h>.
45
46       After exit(), the  exit  status  must  be  transmitted  to  the  parent
47       process.  There are three cases. If the parent has set SA_NOCLDWAIT, or
48       has set the SIGCHLD handler to SIG_IGN, the status is discarded. If the
49       parent  was  waiting on the child it is notified of the exit status. In
50       both cases the exiting process dies immediately. If the parent has  not
51       indicated  that  it  is  not  interested in the exit status, but is not
52       waiting, the exiting process turns into a "zombie"  process  (which  is
53       nothing  but a container for the single byte representing the exit sta‐
54       tus) so that the parent can learn the exit status when it  later  calls
55       one of the wait() functions.
56
57       If  the implementation supports the SIGCHLD signal, this signal is sent
58       to the parent. If the parent has  set  SA_NOCLDWAIT,  it  is  undefined
59       whether a SIGCHLD signal is sent.
60
61       If  the process is a session leader and its controlling terminal is the
62       controlling terminal of the session, then each  process  in  the  fore‐
63       ground process group of this controlling terminal is sent a SIGHUP sig‐
64       nal, and the terminal is disassociated from this session,  allowing  it
65       to be acquired by a new controlling process.
66
67       If  the  exit of the process causes a process group to become orphaned,
68       and if any member of the newly orphaned process group is stopped,  then
69       a  SIGHUP  signal  followed  by  a  SIGCONT signal will be sent to each
70       process in this process group.
71

SEE ALSO

73       _exit(2), wait(2), atexit(3), on_exit(3), tmpfile(3)
74
75
76
77                                  2001-11-17                           EXIT(3)
Impressum