2004-11-03 13:51:07 +00:00
|
|
|
.\" Copyright (C) 2001 Andries Brouwer <aeb@cwi.nl>.
|
|
|
|
.\"
|
|
|
|
.\" Permission is granted to make and distribute verbatim copies of this
|
|
|
|
.\" manual provided the copyright notice and this permission notice are
|
|
|
|
.\" preserved on all copies.
|
|
|
|
.\"
|
|
|
|
.\" Permission is granted to copy and distribute modified versions of this
|
|
|
|
.\" manual under the conditions for verbatim copying, provided that the
|
|
|
|
.\" entire resulting derived work is distributed under the terms of a
|
|
|
|
.\" permission notice identical to this one.
|
|
|
|
.\"
|
|
|
|
.\" Since the Linux kernel and libraries are constantly changing, this
|
|
|
|
.\" manual page may be incorrect or out-of-date. The author(s) assume no
|
|
|
|
.\" responsibility for errors or omissions, or for damages resulting from
|
|
|
|
.\" the use of the information contained herein. The author(s) may not
|
|
|
|
.\" have taken the same level of care in the production of this manual,
|
|
|
|
.\" which is licensed free of charge, as they might when working
|
|
|
|
.\" professionally.
|
|
|
|
.\"
|
|
|
|
.\" Formatted or processed versions of this manual, if unaccompanied by
|
|
|
|
.\" the source, must acknowledge the copyright and authors of this work.
|
|
|
|
.\"
|
|
|
|
.TH EXIT 3 2001-11-17 "" "Linux Programmer's Manual"
|
|
|
|
.SH NAME
|
2005-06-14 11:25:12 +00:00
|
|
|
exit \- cause normal process termination
|
2004-11-03 13:51:07 +00:00
|
|
|
.SH SYNOPSIS
|
|
|
|
.nf
|
|
|
|
.B #include <stdlib.h>
|
|
|
|
.sp
|
|
|
|
.BI "void exit(int " status );
|
|
|
|
.fi
|
|
|
|
.SH DESCRIPTION
|
2005-06-23 09:47:01 +00:00
|
|
|
The \fBexit\fP() function causes normal process termination and the
|
|
|
|
value of \fIstatus & 0377\fP is returned to the parent
|
2004-11-03 13:51:07 +00:00
|
|
|
(see
|
|
|
|
.BR wait (2)).
|
|
|
|
.LP
|
2005-06-23 09:47:01 +00:00
|
|
|
All functions registered with
|
|
|
|
\fBatexit\fP() and \fBon_exit\fP()
|
|
|
|
are called, in the reverse order of their registration.
|
|
|
|
(It is possible for one of these functions to use
|
|
|
|
\fBatexit\fP() or \fBon_exit\fP() to register an additional
|
|
|
|
function to be executed during exit processing;
|
|
|
|
the new registration is added to the front of the list of functions
|
|
|
|
that remain to be called.)
|
|
|
|
.LP
|
|
|
|
All open streams are flushed and closed.
|
|
|
|
Files created by \fBtmpfile\fP() are removed.
|
|
|
|
.LP
|
|
|
|
The C standard specifies two constants,
|
|
|
|
\fIEXIT_SUCCESS\fP and \fIEXIT_FAILURE\fP,
|
|
|
|
that may be passed to \fBexit\fP() to indicate successful or unsuccessful
|
2004-11-03 13:51:07 +00:00
|
|
|
termination, respectively.
|
|
|
|
.SH "RETURN VALUE"
|
2005-06-23 09:47:01 +00:00
|
|
|
The \fBexit\fP() function does not return.
|
2004-11-03 13:51:07 +00:00
|
|
|
.SH "CONFORMING TO"
|
2006-08-03 13:57:30 +00:00
|
|
|
SVr4, 4.3BSD, POSIX.1-2001.
|
2004-11-03 13:51:07 +00:00
|
|
|
.SH NOTES
|
2005-06-14 11:25:12 +00:00
|
|
|
.LP
|
2005-06-23 09:47:01 +00:00
|
|
|
It is undefined what happens if one of the
|
|
|
|
functions registered using \fBatexit\fP() and \fBon_exit\fP()
|
|
|
|
calls either \fBexit\fP() or \fBlongjmp\fP().
|
2004-11-03 13:51:07 +00:00
|
|
|
.LP
|
|
|
|
The use of EXIT_SUCCESS and EXIT_FAILURE is slightly more portable
|
2005-06-15 13:32:34 +00:00
|
|
|
(to non-Unix environments) than that of 0 and some non-zero value
|
2004-11-03 13:51:07 +00:00
|
|
|
like 1 or \-1. In particular, VMS uses a different convention.
|
|
|
|
.LP
|
2005-07-06 08:00:30 +00:00
|
|
|
BSD has attempted to standardize exit codes; see the file
|
2004-11-03 13:51:07 +00:00
|
|
|
.IR <sysexits.h> .
|
|
|
|
.LP
|
2005-06-23 09:47:01 +00:00
|
|
|
After \fBexit\fP(), the exit status must be transmitted to the
|
2004-11-03 13:51:07 +00:00
|
|
|
parent process. There are three cases. If the parent has set
|
|
|
|
SA_NOCLDWAIT, or has set the SIGCHLD handler to SIG_IGN, the
|
|
|
|
status is discarded. If the parent was waiting on the child
|
|
|
|
it is notified of the exit status. In both cases the exiting
|
|
|
|
process dies immediately. If the parent has not indicated that
|
|
|
|
it is not interested in the exit status, but is not waiting,
|
|
|
|
the exiting process turns into a "zombie" process
|
|
|
|
(which is nothing but a container for the single byte representing
|
|
|
|
the exit status) so that the parent can learn the exit status when
|
2005-06-23 09:47:01 +00:00
|
|
|
it later calls one of the \fIwait\fP() functions.
|
2004-11-03 13:51:07 +00:00
|
|
|
.LP
|
|
|
|
If the implementation supports the SIGCHLD signal, this signal
|
|
|
|
is sent to the parent. If the parent has set SA_NOCLDWAIT,
|
|
|
|
it is undefined whether a SIGCHLD signal is sent.
|
|
|
|
.LP
|
|
|
|
If the process is a session leader and its controlling terminal
|
2005-08-04 14:01:47 +00:00
|
|
|
is the controlling terminal of the session, then each process in
|
2004-11-03 13:51:07 +00:00
|
|
|
the foreground process group of this controlling terminal
|
|
|
|
is sent a SIGHUP signal, and the terminal is disassociated
|
|
|
|
from this session, allowing it to be acquired by a new controlling
|
|
|
|
process.
|
|
|
|
.LP
|
|
|
|
If the exit of the process causes a process group to become orphaned,
|
2005-06-14 11:25:12 +00:00
|
|
|
and if any member of the newly orphaned process group is stopped,
|
2004-11-03 13:51:07 +00:00
|
|
|
then a SIGHUP signal followed by a SIGCONT signal will be
|
|
|
|
sent to each process in this process group.
|
|
|
|
.SH "SEE ALSO"
|
|
|
|
.BR _exit (2),
|
|
|
|
.BR wait (2),
|
|
|
|
.BR atexit (3),
|
|
|
|
.BR on_exit (3),
|
|
|
|
.BR tmpfile (3)
|