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