exit(2) exit(2)
NAME
exit, exit - terminate process
SYNOPSIS
#include <stdlib.h>
void exit(int status);
#include <unistd.h>
void exit(int status);
DESCRIPTION
The exit() function calls all functions registered by the atexit()
function, in the reverse order of their registration.
If a function registered by a call to atexit() fails to return, the
remaining registered functions are not called and the rest of the exit
processing is not completed. If the exit() function is called more
than once, the results are undefined.
The exit() function terminates the process without these cleanup
measures.
Once all registered functions have been processed, exit() flushes all
output streams, closes all open streams, and removes all files created
by tmpfile().
exit() and exit() terminate the calling process with the following
consequences:
- All of the file descriptors, directory streams and message catalog
descriptors open in the calling process are closed.
- If the parent process of the calling process is executing a wait(),
wait3(), waitid() or waitpid(), and has neither set its
SANOCLDWAIT flag nor set SIGCHLD to SIGIGN, it is notified of the
calling process' termination and the low-order eight bits (that is,
bits 0377) of status are made 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(), wait3(), waitid() or wait-
pid().
- If the parent process of the calling process is not executing a
wait(), wait3(), waitid() or waitpid(), and has not set its
SANOCLDWAIT flag, or set SIGCHLD to SIGIGN, the calling process
is transformed into a zombie process. A zombie process is an inac-
tive process and it will be deleted at some later time when its
parent process executes wait(), wait3(), waitid() or waitpid().
Page 1 Reliant UNIX 5.44 Printed 11/98
exit(2) exit(2)
- Termination of a process does not directly terminate its children.
The sending of a SIGHUP signal as described below indirectly ter-
minates children in some circumstances.
- If the implementation supports the SIGCHLD signal, a SIGCHLD will
be sent to the parent process.
- The parent process ID of all of the calling process' existing child
processes and zombie processes is set to 1. This means the initial-
ization process inherits each of these processes.
- Each mapped memory object is unmapped.
- Each attached shared memory segment is detached and the value of
shmnattach in the data structure associated with its shared memory
identifier is decremented by 1.
- For each semaphore for which the calling process has set a semadj
value [see semop(2)], that semadj value is added to the semval of
the specified semaphore.
- If the process has a process, text, or data lock, an UNLOCK is per-
formed [see plock(2)].
- An accounting record is written on the accounting file if the
system's accounting routine is enabled [see acct(2)].
- If the process is a controlling process, SIGHUP is sent to the
foreground process group of its controlling terminal and its con-
trolling terminal is deallocated.
- 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 process.
- 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 SIGHUP
and SIGCONT signals.
- If the parent process has set its SANOCLDWAIT flag, or set SIGCHLD
to SIGIGN, the status will be discarded, and the lifetime of the
calling process will end immediately.
The symbols EXITSUCCESS and EXITFAILURE are defined in stdlib.h and
may be used as the value of status to indicate successful or unsuc-
cessful termination, respectively.
NOTES
See NOTES section under signal(2).
Page 2 Reliant UNIX 5.44 Printed 11/98
exit(2) exit(2)
SEE ALSO
acct(2), plock(2), semop(2), sigaction(2), signal(2), times(2),
wait(2), atexit(3C).
Page 3 Reliant UNIX 5.44 Printed 11/98