xref: /openbsd-src/lib/libc/sys/_exit.2 (revision 743bf1555bada8d2af984d6a19b71a47862d1fa7)
1*743bf155Sjsg.\"	$OpenBSD: _exit.2,v 1.23 2022/02/18 00:15:53 jsg Exp $
2df930be7Sderaadt.\"	$NetBSD: _exit.2,v 1.6 1995/02/27 12:31:34 cgd Exp $
3df930be7Sderaadt.\"
4df930be7Sderaadt.\" Copyright (c) 1980, 1993
5df930be7Sderaadt.\"	The Regents of the University of California.  All rights reserved.
6df930be7Sderaadt.\"
7df930be7Sderaadt.\" Redistribution and use in source and binary forms, with or without
8df930be7Sderaadt.\" modification, are permitted provided that the following conditions
9df930be7Sderaadt.\" are met:
10df930be7Sderaadt.\" 1. Redistributions of source code must retain the above copyright
11df930be7Sderaadt.\"    notice, this list of conditions and the following disclaimer.
12df930be7Sderaadt.\" 2. Redistributions in binary form must reproduce the above copyright
13df930be7Sderaadt.\"    notice, this list of conditions and the following disclaimer in the
14df930be7Sderaadt.\"    documentation and/or other materials provided with the distribution.
156580fee3Smillert.\" 3. Neither the name of the University nor the names of its contributors
16df930be7Sderaadt.\"    may be used to endorse or promote products derived from this software
17df930be7Sderaadt.\"    without specific prior written permission.
18df930be7Sderaadt.\"
19df930be7Sderaadt.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20df930be7Sderaadt.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21df930be7Sderaadt.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22df930be7Sderaadt.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23df930be7Sderaadt.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24df930be7Sderaadt.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25df930be7Sderaadt.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26df930be7Sderaadt.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27df930be7Sderaadt.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28df930be7Sderaadt.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29df930be7Sderaadt.\" SUCH DAMAGE.
30df930be7Sderaadt.\"
31df930be7Sderaadt.\"     @(#)_exit.2	8.1 (Berkeley) 6/4/93
32df930be7Sderaadt.\"
33*743bf155Sjsg.Dd $Mdocdate: February 18 2022 $
34bb84f009Saaron.Dt _EXIT 2
35fc8533a3Saaron.Os
36df930be7Sderaadt.Sh NAME
3789e2fe5cSguenther.Nm _exit ,
3889e2fe5cSguenther.Nm _Exit
39df930be7Sderaadt.Nd terminate the calling process
40df930be7Sderaadt.Sh SYNOPSIS
41ec5cd23eSschwarze.In unistd.h
42df930be7Sderaadt.Ft void
43df930be7Sderaadt.Fn _exit "int status"
44ec5cd23eSschwarze.In stdlib.h
4589e2fe5cSguenther.Ft void
4689e2fe5cSguenther.Fn _Exit "int status"
47df930be7Sderaadt.Sh DESCRIPTION
48df930be7SderaadtThe
49df930be7Sderaadt.Fn _exit
5089e2fe5cSguentherand
5189e2fe5cSguenther.Fn _Exit
5289e2fe5cSguentherfunctions terminate a process with the following consequences:
53df930be7Sderaadt.Bl -bullet
54df930be7Sderaadt.It
5589e2fe5cSguentherAll threads in the process are terminated.
5689e2fe5cSguenther.It
57bb84f009SaaronAll open file descriptors in the calling process are closed.
58a4a5a972SaaronThis may entail delays; for example, waiting for output to drain.
59a4a5a972SaaronA process in this state may not be killed, as it is already dying.
60df930be7Sderaadt.It
61df930be7SderaadtIf the parent process of the calling process has an outstanding
624e001e45Sderaadt.Xr wait 2
63ea418ffeSaaroncall or catches the
64df930be7Sderaadt.Dv SIGCHLD
65ea418ffeSaaronsignal, it is notified of the calling process's termination and
66a4a5a972Saaron.Fa status
67df930be7Sderaadtis set as defined by
68df930be7Sderaadt.Xr wait 2 .
69ad9bd2c5Sderaadt(Note that typically only the lower 8 bits of
70ad9bd2c5Sderaadt.Fa status
717cbfd693Sjmcare passed on to the parent, thus negative values have less meaning.)
72df930be7Sderaadt.It
73a4a5a972SaaronThe parent process ID of all of the calling process's existing child
74ea418ffeSaaronprocesses are set to 1; the initialization process (see the
7560addc80SjmcDEFINITIONS section of
76df930be7Sderaadt.Xr intro 2 )
77df930be7Sderaadtinherits each of these processes.
78df930be7Sderaadt.It
79df930be7SderaadtIf the termination of the process causes any process group
80df930be7Sderaadtto become orphaned (usually because the parents of all members
8160addc80Sjmcof the group have now exited; see Orphaned Process Group in
82df930be7Sderaadt.Xr intro 2 ) ,
83ea418ffeSaaronand if any member of the orphaned group is stopped, the
84df930be7Sderaadt.Dv SIGHUP
85a4a5a972Saaronand
86df930be7Sderaadt.Dv SIGCONT
87a4a5a972Saaronsignals are sent to all members of the newly orphaned process group.
88df930be7Sderaadt.It
89df930be7SderaadtIf the process is a controlling process (see
90df930be7Sderaadt.Xr intro 2 ) ,
91df930be7Sderaadtthe
92df930be7Sderaadt.Dv SIGHUP
93df930be7Sderaadtsignal is sent to the foreground process group of the controlling terminal,
94df930be7Sderaadtand all current access to the controlling terminal is revoked.
95df930be7Sderaadt.El
96df930be7Sderaadt.Pp
97df930be7SderaadtMost C programs call the library routine
98df930be7Sderaadt.Xr exit 3 ,
99df930be7Sderaadtwhich flushes buffers, closes streams, unlinks temporary files, etc.,
1001e7e370bSderaadtand then calls
101df930be7Sderaadt.Fn _exit .
1021106d8b7Saaron.Sh RETURN VALUES
103df930be7Sderaadt.Fn _exit
10489e2fe5cSguentherand
10589e2fe5cSguenther.Fn _Exit
106df930be7Sderaadtcan never return.
107df930be7Sderaadt.Sh SEE ALSO
108df930be7Sderaadt.Xr fork 2 ,
109bb84f009Saaron.Xr intro 2 ,
110df930be7Sderaadt.Xr sigaction 2 ,
111df930be7Sderaadt.Xr wait 2 ,
11251daf57cSfgsch.Xr exit 3 ,
11351daf57cSfgsch.Xr sysexits 3
114df930be7Sderaadt.Sh STANDARDS
115df930be7SderaadtThe
116a4a5a972Saaron.Fn _exit
117*743bf155Sjsgfunction conforms to
11889e2fe5cSguenther.St -p1003.1-2008 .
11989e2fe5cSguentherThe
12089e2fe5cSguenther.Fn _Exit
12189e2fe5cSguentherfunction conforms to
1221b0e3e11Sschwarze.St -isoC-99 .
1234de47393Sschwarze.Sh HISTORY
1244de47393SschwarzeAn
1254de47393Sschwarze.Fn exit
1264de47393Sschwarzesystem call first appeared in
12723fbb714Sschwarze.At v1 .
12823fbb714SschwarzeIt accepts the
12923fbb714Sschwarze.Fa status
13023fbb714Sschwarzeargument since
13123fbb714Sschwarze.At v2 .
13223fbb714SschwarzeAn
1334de47393Sschwarze.Fn _exit
13423fbb714Sschwarzevariant first appeared in
1354de47393Sschwarze.At v7 .
13689e2fe5cSguentherThe
13789e2fe5cSguenther.Fn _Exit
13889e2fe5cSguentherfunction appeared in
13989e2fe5cSguenther.Ox 3.6 .
140