1exit(2)                          System Calls                          exit(2)
2
3
4

NAME

6       exit, _Exit, _exit - terminate process
7

SYNOPSIS

9       #include <stdlib.h>
10
11       void exit(int status);
12
13
14       void _Exit(int status);
15
16
17       #include <unistd.h>
18
19       void _exit(int status);
20
21

DESCRIPTION

23       The exit() function first calls all functions registered by atexit(3C),
24       in the reverse order of their registration, except that a  function  is
25       called  after any previously registered functions that had already been
26       called at the time it was registered. Each function is called  as  many
27       times as it was registered. If, during the call to any such function, a
28       call to the longjmp(3C) function is made that would terminate the  call
29       to the registered function, the behavior is undefined.
30
31
32       If  a  function registered by a call to atexit(3C) fails to return, the
33       remaining registered functions are not  called  and  the  rest  of  the
34       exit() processing is not completed. If exit() is called more than once,
35       the effects are undefined.
36
37
38       The exit() function  then  flushes  all  open  streams  with  unwritten
39       buffered  data,  closes all open streams, and removes all files created
40       by tmpfile(3C).
41
42
43       The _Exit() and _exit() functions are functionally equivalent. They  do
44       not call functions registered with atexit(), do not call any registered
45       signal handlers, and do not flush open streams.
46
47
48       The _exit(),  _Exit(),  and  exit()  functions  terminate  the  calling
49       process with the following consequences:
50
51           o      All  of  the file descriptors, directory streams, conversion
52                  descriptors and message catalogue descriptors  open  in  the
53                  calling process are closed.
54
55           o      If  the parent process of the calling process is executing a
56                  wait(3C), wait3(3C), waitid(2), or waitpid(3C), and has nei‐
57                  ther  set  its SA_NOCLDWAIT flag nor set SIGCHLD to SIG_IGN,
58                  it is notified of the calling process's termination and  the
59                  low-order eight bits (that is, bits 0377) of status are made
60                  available to it.  If the parent is not waiting, the  child's
61                  status  will  be made available to it when the parent subse‐
62                  quently executes wait(), wait3(), waitid(), or waitpid().
63
64           o      If the parent process of the calling process is not  execut‐
65                  ing  a  wait(), wait3(), waitid(), or waitpid(), and has not
66                  set its SA_NOCLDWAIT flag, or set SIGCHLD  to  SIG_IGN,  the
67                  calling process is transformed into a zombie process. A zom‐
68                  bie process is an inactive process and it will be deleted at
69                  some  later  time  when  its parent process executes wait(),
70                  wait3(), waitid(), or waitpid(). A zombie process only occu‐
71                  pies  a  slot  in  the  process table; it has no other space
72                  allocated either in user or kernel space. The process  table
73                  slot  that  it  occupies  is  partially  overlaid  with time
74                  accounting information (see <sys/proc.h>) to be used by  the
75                  times(2) function.
76
77           o      Termination  of  a  process  does not directly terminate its
78                  children. The sending of a SIGHUP signal as described  below
79                  indirectly terminates children in some circumstances.
80
81           o      A SIGCHLD will be sent to the parent process.
82
83           o      The parent process ID of all of the calling process's exist‐
84                  ing child processes and zombie processes is set to  1.  That
85                  is,  these  processes  are  inherited  by the initialization
86                  process (see Intro(2)).
87
88           o      Each mapped memory object is unmapped.
89
90           o      Each attached shared-memory  segment  is  detached  and  the
91                  value  of  shm_nattch  (see shmget(2)) in the data structure
92                  associated with its shared memory ID is decremented by 1.
93
94           o      For each semaphore for which the calling process has  set  a
95                  semadj value (see semop(2)), that value is added to the sem‐
96                  val of the specified semaphore.
97
98           o      If the process is a controlling process, the  SIGHUP  signal
99                  will be sent to each process in the foreground process group
100                  of  the  controlling  terminal  belonging  to  the   calling
101                  process.
102
103           o      If  the  process  is  a controlling process, the controlling
104                  terminal associated with the session is  disassociated  from
105                  the session, allowing it to be acquired by a new controlling
106                  process.
107
108           o      If the exit of the process causes a process group to  become
109                  orphaned,  and  if  any member of the newly-orphaned process
110                  group is stopped, then a SIGHUP signal followed by a SIGCONT
111                  signal  will  be  sent to each process in the newly-orphaned
112                  process group.
113
114           o      If the parent process has set its SA_NOCLDWAIT flag, or  set
115                  SIGCHLD  to  SIG_IGN,  the status will be discarded, and the
116                  lifetime of the calling process will end immediately.
117
118           o      If the process has process, text or data locks, an UNLOCK is
119                  performed (see plock(3C) and memcntl(2)).
120
121           o      All open named semaphores in the process are closed as if by
122                  appropriate calls to sem_close(3C). All open message  queues
123                  in  the  process  are  closed  as if by appropriate calls to
124                  mq_close(3C). Any outstanding  asynchronous  I/O  operations
125                  may be cancelled.
126
127           o      An  accounting  record  is written on the accounting file if
128                  the system's accounting routine is enabled (see acct(2)).
129
130           o      An extended accounting record is  written  to  the  extended
131                  process  accounting  file  if  the system's extended process
132                  accounting facility is enabled (see acctadm(1M)).
133
134           o      If the current process is the last process within  its  task
135                  and  if  the  system's  extended task accounting facility is
136                  enabled (see acctadm(1M)), an extended accounting record  is
137                  written to the extended task accounting file.
138

RETURN VALUES

140       These functions do not return.
141

ERRORS

143       No errors are defined.
144

USAGE

146       Normally applications should use exit() rather than _exit().
147

ATTRIBUTES

149       See attributes(5) for descriptions of the following attributes:
150
151
152
153
154       ┌─────────────────────────────┬─────────────────────────────┐
155       │      ATTRIBUTE TYPE         │      ATTRIBUTE VALUE        │
156       ├─────────────────────────────┼─────────────────────────────┤
157       │Interface Stability          │Committed                    │
158       ├─────────────────────────────┼─────────────────────────────┤
159       │MT-Level                     │See below.                   │
160       ├─────────────────────────────┼─────────────────────────────┤
161       │Standard                     │See standards(5).            │
162       └─────────────────────────────┴─────────────────────────────┘
163
164
165       The _exit() and _Exit() functions are Async-Signal-Safe.
166

SEE ALSO

168       acctadm(1M),   Intro(2),   acct(2),   close(2),  memcntl(2),  semop(2),
169       shmget(2), sigaction(2), times(2), waitid(2),  atexit(3C),  fclose(3C),
170       mq_close(3C),   plock(3C),   signal.h(3HEAD),   tmpfile(3C),  wait(3C),
171       wait3(3C), waitpid(3C), attributes(5), standards(5)
172
173
174
175SunOS 5.11                        5 Feb 2008                           exit(2)
Impressum