xref: /openbsd/lib/libc/sys/_exit.2 (revision 73471bf0)
1.\"	$OpenBSD: _exit.2,v 1.22 2015/09/10 17:55:21 schwarze Exp $
2.\"	$NetBSD: _exit.2,v 1.6 1995/02/27 12:31:34 cgd Exp $
3.\"
4.\" Copyright (c) 1980, 1993
5.\"	The Regents of the University of California.  All rights reserved.
6.\"
7.\" Redistribution and use in source and binary forms, with or without
8.\" modification, are permitted provided that the following conditions
9.\" are met:
10.\" 1. Redistributions of source code must retain the above copyright
11.\"    notice, this list of conditions and the following disclaimer.
12.\" 2. Redistributions in binary form must reproduce the above copyright
13.\"    notice, this list of conditions and the following disclaimer in the
14.\"    documentation and/or other materials provided with the distribution.
15.\" 3. Neither the name of the University nor the names of its contributors
16.\"    may be used to endorse or promote products derived from this software
17.\"    without specific prior written permission.
18.\"
19.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29.\" SUCH DAMAGE.
30.\"
31.\"     @(#)_exit.2	8.1 (Berkeley) 6/4/93
32.\"
33.Dd $Mdocdate: September 10 2015 $
34.Dt _EXIT 2
35.Os
36.Sh NAME
37.Nm _exit ,
38.Nm _Exit
39.Nd terminate the calling process
40.Sh SYNOPSIS
41.In unistd.h
42.Ft void
43.Fn _exit "int status"
44.In stdlib.h
45.Ft void
46.Fn _Exit "int status"
47.Sh DESCRIPTION
48The
49.Fn _exit
50and
51.Fn _Exit
52functions terminate a process with the following consequences:
53.Bl -bullet
54.It
55All threads in the process are terminated.
56.It
57All open file descriptors in the calling process are closed.
58This may entail delays; for example, waiting for output to drain.
59A process in this state may not be killed, as it is already dying.
60.It
61If the parent process of the calling process has an outstanding
62.Xr wait 2
63call or catches the
64.Dv SIGCHLD
65signal, it is notified of the calling process's termination and
66.Fa status
67is set as defined by
68.Xr wait 2 .
69(Note that typically only the lower 8 bits of
70.Fa status
71are passed on to the parent, thus negative values have less meaning.)
72.It
73The parent process ID of all of the calling process's existing child
74processes are set to 1; the initialization process (see the
75DEFINITIONS section of
76.Xr intro 2 )
77inherits each of these processes.
78.It
79If the termination of the process causes any process group
80to become orphaned (usually because the parents of all members
81of the group have now exited; see Orphaned Process Group in
82.Xr intro 2 ) ,
83and if any member of the orphaned group is stopped, the
84.Dv SIGHUP
85and
86.Dv SIGCONT
87signals are sent to all members of the newly orphaned process group.
88.It
89If the process is a controlling process (see
90.Xr intro 2 ) ,
91the
92.Dv SIGHUP
93signal is sent to the foreground process group of the controlling terminal,
94and all current access to the controlling terminal is revoked.
95.El
96.Pp
97Most C programs call the library routine
98.Xr exit 3 ,
99which flushes buffers, closes streams, unlinks temporary files, etc.,
100and then calls
101.Fn _exit .
102.Sh RETURN VALUES
103.Fn _exit
104and
105.Fn _Exit
106can never return.
107.Sh SEE ALSO
108.Xr fork 2 ,
109.Xr intro 2 ,
110.Xr sigaction 2 ,
111.Xr wait 2 ,
112.Xr exit 3 ,
113.Xr sysexits 3
114.Sh STANDARDS
115The
116.Fn _exit
117function conform to
118.St -p1003.1-2008 .
119The
120.Fn _Exit
121function conforms to
122.St -isoC-99 .
123.Sh HISTORY
124An
125.Fn exit
126system call first appeared in
127.At v1 .
128It accepts the
129.Fa status
130argument since
131.At v2 .
132An
133.Fn _exit
134variant first appeared in
135.At v7 .
136The
137.Fn _Exit
138function appeared in
139.Ox 3.6 .
140