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       noreturn void exit(int status);
12

DESCRIPTION

14       The  exit()  function  causes  normal process termination and the least
15       significant byte of status (i.e., status & 0xFF)  is  returned  to  the
16       parent (see wait(2)).
17
18       All  functions  registered with atexit(3) and on_exit(3) are called, in
19       the reverse order of their registration.  (It is possible  for  one  of
20       these  functions  to  use  atexit(3) or on_exit(3) to register an addi‐
21       tional function to be executed during exit processing; the  new  regis‐
22       tration  is  added to the front of the list of functions that remain to
23       be called.)  If one of these functions does not return (e.g., it  calls
24       _exit(2),  or  kills  itself with a signal), then none of the remaining
25       functions is called, and further exit processing (in particular, flush‐
26       ing  of  stdio(3) streams) is abandoned.  If a function has been regis‐
27       tered multiple times using atexit(3) or on_exit(3), then it  is  called
28       as many times as it was registered.
29
30       All  open  stdio(3)  streams  are flushed and closed.  Files created by
31       tmpfile(3) are removed.
32
33       The C standard specifies two constants, EXIT_SUCCESS and  EXIT_FAILURE,
34       that  may  be  passed  to exit() to indicate successful or unsuccessful
35       termination, respectively.
36

RETURN VALUE

38       The exit() function does not return.
39

ATTRIBUTES

41       For an  explanation  of  the  terms  used  in  this  section,  see  at‐
42       tributes(7).
43
44       ┌────────────────────────────────┬───────────────┬─────────────────────┐
45Interface                       Attribute     Value               
46       ├────────────────────────────────┼───────────────┼─────────────────────┤
47exit()                          │ Thread safety │ MT-Unsafe race:exit │
48       └────────────────────────────────┴───────────────┴─────────────────────┘
49
50       The exit() function uses a global variable that is not protected, so it
51       is not thread-safe.
52

CONFORMING TO

54       POSIX.1-2001, POSIX.1-2008, C89, C99, SVr4, 4.3BSD.
55

NOTES

57       The behavior is undefined if one  of  the  functions  registered  using
58       atexit(3)  and on_exit(3) calls either exit() or longjmp(3).  Note that
59       a call to execve(2) removes registrations created using  atexit(3)  and
60       on_exit(3).
61
62       The  use of EXIT_SUCCESS and EXIT_FAILURE is slightly more portable (to
63       non-UNIX environments) than the use of 0 and some nonzero value like  1
64       or -1.  In particular, VMS uses a different convention.
65
66       BSD  has  attempted  to  standardize exit codes (which some C libraries
67       such as the GNU C library have also  adopted);  see  the  file