]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man2/_exit.2
getsid.2: deduplicate getsid(0) case
[thirdparty/man-pages.git] / man2 / _exit.2
CommitLineData
fea681da 1.\" This manpage is Copyright (C) 1992 Drew Eckhardt;
ac56b6a8 2.\" and Copyright (C) 1993 Michael Haardt, Ian Jackson.
fea681da 3.\"
5fbde956 4.\" SPDX-License-Identifier: Linux-man-pages-copyleft
fea681da
MK
5.\"
6.\" Modified Wed Jul 21 23:02:38 1993 by Rik Faith <faith@cs.unc.edu>
7.\" Modified 2001-11-17, aeb
8.\"
1d767b55 9.TH _EXIT 2 2021-03-22 "Linux" "Linux Programmer's Manual"
fea681da 10.SH NAME
a1ffe9f5 11_exit, _Exit \- terminate the calling process
edf2e4a8
AC
12.SH LIBRARY
13Standard C library
8fc3b2cf 14.RI ( libc ", " \-lc )
fea681da 15.SH SYNOPSIS
c7db92b9 16.nf
fea681da 17.B #include <unistd.h>
68e4db0a 18.PP
d8a9e2bb 19.BI "noreturn void _exit(int " status );
eaa18d3c 20.PP
fea681da 21.B #include <stdlib.h>
68e4db0a 22.PP
d8a9e2bb 23.BI "noreturn void _Exit(int " status );
c7db92b9 24.fi
68e4db0a 25.PP
d39ad78f 26.RS -4
cc4615cc
MK
27Feature Test Macro Requirements for glibc (see
28.BR feature_test_macros (7)):
d39ad78f 29.RE
68e4db0a 30.PP
cc4615cc 31.BR _Exit ():
9d2adbae 32.nf
5c10d2c5 33 _ISOC99_SOURCE || _POSIX_C_SOURCE >= 200112L
9d2adbae 34.fi
fea681da 35.SH DESCRIPTION
63aa9df0 36.BR _exit ()
c13182ef 37terminates the calling process "immediately".
55873ed6 38Any open file descriptors belonging to the process are closed.
99ed723a 39Any children of the process are inherited by
a88f0e06 40.BR init (1)
99ed723a
MK
41(or by the nearest "subreaper" process as defined through the use of the
42.BR prctl (2)
43.B PR_SET_CHILD_SUBREAPER
44operation).
55873ed6 45The process's parent is sent a
fea681da
MK
46.B SIGCHLD
47signal.
dd3568a1 48.PP
fea681da 49The value
f3491e47 50.I "status & 0xFF"
fea681da 51is returned to the parent process as the process's exit status, and
07f462e9 52can be collected by the parent using one of the
0bfa087b 53.BR wait (2)
fea681da 54family of calls.
dd3568a1 55.PP
fea681da 56The function
63aa9df0 57.BR _Exit ()
fea681da 58is equivalent to
63aa9df0 59.BR _exit ().
47297adb 60.SH RETURN VALUE
fea681da 61These functions do not return.
47297adb 62.SH CONFORMING TO
5a3b5c1d 63POSIX.1-2001, POSIX.1-2008, SVr4, 4.3BSD.
60a90ecd
MK
64The function
65.BR _Exit ()
66was introduced by C99.
fea681da
MK
67.SH NOTES
68For a discussion on the effects of an exit, the transmission of
078a7d6e 69exit status, zombie processes, signals sent, and so on, see
fea681da 70.BR exit (3).
dd3568a1 71.PP
fea681da 72The function
63aa9df0 73.BR _exit ()
60a90ecd
MK
74is like
75.BR exit (3),
76but does not call any
7b57506d 77functions registered with
0bfa087b 78.BR atexit (3)
c13182ef 79or
0bfa087b 80.BR on_exit (3).
29c4533c
MK
81Open
82.BR stdio (3)
83streams are not flushed.
fea681da 84On the other hand,
63aa9df0 85.BR _exit ()
fea681da 86does close open file descriptors, and this may cause an unknown delay,
c13182ef
MK
87waiting for pending output to finish.
88If the delay is undesired,
988db661 89it may be useful to call functions like
0bfa087b 90.BR tcflush (3)
60a90ecd
MK
91before calling
92.BR _exit ().
d9bfdb9c
MK
93Whether any pending I/O is canceled, and which pending I/O may be
94canceled upon
60a90ecd
MK
95.BR _exit (),
96is implementation-dependent.
0722a578 97.SS C library/kernel differences
d99b5be0
MK
98The text above in DESCRIPTION describes the traditional effect of
99.BR _exit (),
100which is to terminate a process,
101and these are the semantics specified by POSIIX.1 and implemented
102by the C library wrapper function.
103On modern systems, this means termination of all threads in the process.
737a840d 104.PP
d99b5be0 105By contrast with the C library wrapper function, the raw Linux
cd356fa1 106.BR _exit ()
737a840d
MK
107system call terminates only the calling thread, and actions such as
108reparenting child processes or sending
109.B SIGCHLD
110to the parent process are performed only if this is
111the last thread in the thread group.
112.\" _exit() is used by pthread_exit() to terminate the calling thread
d99b5be0
MK
113.PP
114In glibc up to version 2.3, the
115.BR _exit ()
116wrapper function invoked the kernel system call of the same name.
117Since glibc 2.3, the wrapper function invokes
118.BR exit_group (2),
119in order to terminate all of the threads in a process.
47297adb 120.SH SEE ALSO
fea681da 121.BR execve (2),
f02720dd 122.BR exit_group (2),
fea681da
MK
123.BR fork (2),
124.BR kill (2),
125.BR wait (2),
126.BR wait4 (2),
127.BR waitpid (2),
7b57506d 128.BR atexit (3),
fea681da 129.BR exit (3),
7b57506d 130.BR on_exit (3),
fea681da 131.BR termios (3)