EXIT(2) System Calls EXIT(2)
exit, _Exit, _exit - terminate process
#include <stdlib.h> void exit
); void _Exit
#include <unistd.h> void _exit
function first calls all functions registered by atexit(3C)
in the reverse order of their registration, except that a function is
called after any previously registered functions that had already been
called at the time it was registered. Each function is called as many
times as it was registered. If, during the call to any such function, a
call to the longjmp(3C)
function is made that would terminate the call to
the registered function, the behavior is undefined.
If a function registered by a call to atexit(3C)
fails to return, the
remaining registered functions are not called and the rest of the exit()
processing is not completed. If exit()
is called more than once, the
effects are undefined.
function then flushes all open streams with unwritten buffered
data, closes all open streams, and removes all files created by tmpfile(3C)
functions are functionally equivalent. They do
not call functions registered with atexit()
, do not call any registered
signal handlers, and do not flush open streams.
, and exit()
functions terminate the calling process
with the following consequences:
o All of the file descriptors, directory streams, conversion
descriptors and message catalogue descriptors open in the
calling process are closed.
o If the parent process of the calling process is executing a wait(3C)
, or waitpid(3C)
, and has
neither set its SA_NOCLDWAIT
flag nor set SIGCHLD
it is notified of the calling process's termination and the
low-order eight bits (that is, bits 0377) of status
available to it. If the parent is not waiting, the child's
status will be made available to it when the parent
subsequently executes wait()
, or waitpid()
o If the parent process of the calling process is not executing
, or waitpid()
, and has not set its SA_NOCLDWAIT
flag, or set SIGCHLD
, the calling
process is transformed into a zombie process
. A zombie process
is an inactive process and it will be deleted at some later
time when its parent process executes wait()
, or waitpid()
. A zombie process only occupies a slot
in the process table; it has no other space allocated either
in user or kernel space. The process table slot that it
occupies is partially overlaid with time accounting
information (see <sys/proc.h>
) to be used by the times(2)
o Termination of a process does not directly terminate its
children. The sending of a SIGHUP
signal as described below
indirectly terminates children in some circumstances.
o A SIGCHLD
will be sent to the parent process.
o The parent process ID
of all of the calling process's existing
child processes and zombie processes is set to 1. That is,
these processes are inherited by the initialization process
o Each mapped memory object is unmapped.
o Each attached shared-memory segment is detached and the value
) in the data structure associated
with its shared memory ID
is decremented by 1.
o For each semaphore for which the calling process has set a semadj
value (see semop(2)
), that value is added to the semval
of the specified semaphore.
o If the process is a controlling process, the SIGHUP
will be sent to each process in the foreground process group
of the controlling terminal belonging to the calling process.
o If the process is a controlling process, the controlling
terminal associated with the session is disassociated from the
session, allowing it to be acquired by a new controlling
o If the exit of the process causes a process group to become
orphaned, and if any member of the newly-orphaned process
group is stopped, then a SIGHUP
signal followed by a SIGCONT
signal will be sent to each process in the newly-orphaned
o If the parent process has set its SA_NOCLDWAIT
flag, or set SIGCHLD
, the status will be discarded, and the
lifetime of the calling process will end immediately.
o If the process has process, text or data locks, an UNLOCK
performed (see plock(3C)
o All open named semaphores in the process are closed as if by
appropriate calls to sem_close(3C)
. All open message queues in
the process are closed as if by appropriate calls to mq_close(3C)
. Any outstanding asynchronous I/O operations may
o An accounting record is written on the accounting file if the
system's accounting routine is enabled (see acct(2)
o An extended accounting record is written to the extended
process accounting file if the system's extended process
accounting facility is enabled (see acctadm(1M)
o If the current process is the last process within its task and
if the system's extended task accounting facility is enabled
), an extended accounting record is written to
the extended task accounting file.
These functions do not return.
No errors are defined.
Normally applications should use exit()
rather than _exit()
for descriptions of the following attributes:
| ATTRIBUTE TYPE | ATTRIBUTE VALUE |
|Interface Stability | Committed |
|MT-Level | See below. |
|Standard | See standards(5)
functions are Async-Signal-Safe.
SEE ALSO acctadm(1M)
February 5, 2008 EXIT(2)