'\"macro stdmacro
.if n .pH g2.exit @(#)exit	40.15 of 10/10/89
.\" Copyright 1989 AT&T
.nr X
.if \nX=0 .ds x} exit 2 "" "\&"
.if \nX=1 .ds x} exit 2 ""
.if \nX=2 .ds x} exit 2 "" "\&"
.if \nX=3 .ds x} exit "" "" "\&"
.TH \*(x}
.SH NAME
\f4exit\f1, \f4_exit\f1 \- terminate process
.SH SYNOPSIS
\f4#include <stdlib.h>\f1
.PP
\f4void exit(int status);\f1
.PP
\f4#include <unistd.h>\f1
.PP
\f4void _exit(int status);\f1
.br
.SH DESCRIPTION
\f4_exit\fP
terminates the calling process with the following consequences:
.IP
All of the file descriptors, directory streams and message catalogue
descriptors open in the calling process are closed.
.IP
A \f4SIGCHLD\fP signal is sent to the calling process's parent process.
.IP
If the parent process of the calling process has not specified the
\f4SA_NOCLDWAIT\fP flag [see \f4sigaction\fP(2)],
the calling process is transformed into a ``zombie process.''
A
zombie process
is a process that 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
\f4<sys/proc.h>\fP]
to be used by the
\f4times\fP system call.
.IP
The parent process
.SM ID
of all of the calling process's existing
child processes  and zombie processes is set to 1.
This means the initialization process [see
\f4intro\fP(2)]
inherits each of these processes.
.IP
Each attached shared memory segment is detached and the value of
\f4shm_nattach\f1
in the data structure associated with its shared memory identifier
is decremented by 1.
.IP
For each semaphore for which the calling process has set a \f4semadj\fP value [see
\f4semop\fP(2)],
that \f4semadj\fP value is added to the \f4semval\fP of the specified semaphore.
.IP
If the process has a process, text, or data lock, an
.I unlock\^
is performed [see
\f4plock\fP(2)].
.IP
An accounting record is written on the accounting file if the system's 
accounting routine is enabled [see
\f4acct\fP(2)].
.IP
If the process is a controlling process,
\f4SIGHUP\f1
is sent to the foreground process group of its controlling terminal and
its controlling terminal is deallocated.
.IP
If the calling process has any stopped children whose process group
will be orphaned when the calling process exits, or if the calling
process is a member of
a process group that will be orphaned when the calling process exits,
that process group will be sent
\f4SIGHUP\f1
and
\f4SIGCONT\f1
signals.
.PP
The C function
\f4exit\fP(3C)
calls any functions registered through the
\f4atexit\f1 function in the reverse order
of their registration.
The function
\f4_exit\fP
circumvents all such functions and cleanup.
.PP
The symbols \f4EXIT_SUCCESS\fP and \f4EXIT_FAILURE\fP are defined in
\f4stdlib.h\fP and may be used as the value of \f2status\fP to indicate
successful or unsuccessful termination, respectively.
.SH "SEE ALSO"
\f4acct\fP(2), \f4intro\fP(2), \f4plock\fP(2),
\f4semop\fP(2), \f4sigaction\fP(2), \f4signal\fP(2),
\f4times\fP(2), \f4wait\fP(2), \f4atexit\f1(3C).
.SH NOTES
See \f4signal\fP(2)
\s-1NOTES\s0.
.\"	@(#)exit.2	6.2 of 9/6/83
.Ee
