Debian Codegraph @

upstream/debian-trixie/man2/_exit.2

raw
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 <[email protected]>
7 .\" Modified 2001-11-17, aeb
8 .\"
9 .TH _exit 2 2024-05-02 "Linux man-pages 6.9.1"
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 .P
19 .BI "[[noreturn]] void _exit(int " status );
20 .P
21 .B #include <stdlib.h>
22 .P
23 .BI "[[noreturn]] void _Exit(int " status );
24 .fi
25 .P
26 .RS -4
27 Feature Test Macro Requirements for glibc (see
28 .BR feature_test_macros (7)):
29 .RE
30 .P
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 .P
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 .P
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 .TP
64 .BR _exit ()
65 POSIX.1-2008.
66 .TP
67 .BR _Exit ()
68 C11, POSIX.1-2008.
69 .SH HISTORY
70 POSIX.1-2001, SVr4, 4.3BSD.
71 .P
72 .BR _Exit ()
73 was introduced by C99.
74 .SH NOTES
75 For a discussion on the effects of an exit, the transmission of
76 exit status, zombie processes, signals sent, and so on, see
77 .BR exit (3).
78 .P
79 The function
80 .BR _exit ()
81 is like
82 .BR exit (3),
83 but does not call any
84 functions registered with
85 .BR atexit (3)
86 or
87 .BR on_exit (3).
88 Open
89 .BR stdio (3)
90 streams are not flushed.
91 On the other hand,
92 .BR _exit ()
93 does close open file descriptors, and this may cause an unknown delay,
94 waiting for pending output to finish.
95 If the delay is undesired,
96 it may be useful to call functions like
97 .BR tcflush (3)
98 before calling
99 .BR _exit ().
100 Whether any pending I/O is canceled, and which pending I/O may be
101 canceled upon
102 .BR _exit (),
103 is implementation-dependent.
104 .SS C library/kernel differences
105 The text above in DESCRIPTION describes the traditional effect of
106 .BR _exit (),
107 which is to terminate a process,
108 and these are the semantics specified by POSIX.1 and implemented
109 by the C library wrapper function.
110 On modern systems, this means termination of all threads in the process.
111 .P
112 By contrast with the C library wrapper function, the raw Linux
113 .BR _exit ()
114 system call terminates only the calling thread, and actions such as
115 reparenting child processes or sending
116 .B SIGCHLD
117 to the parent process are performed only if this is
118 the last thread in the thread group.
119 .\" _exit() is used by pthread_exit() to terminate the calling thread
120 .P
121 Up to glibc 2.3, the
122 .BR _exit ()
123 wrapper function invoked the kernel system call of the same name.
124 Since glibc 2.3, the wrapper function invokes
125 .BR exit_group (2),
126 in order to terminate all of the threads in a process.
127 .SH SEE ALSO
128 .BR execve (2),
129 .BR exit_group (2),
130 .BR fork (2),
131 .BR kill (2),
132 .BR wait (2),
133 .BR wait4 (2),
134 .BR waitpid (2),
135 .BR atexit (3),
136 .BR exit (3),
137 .BR on_exit (3),
138 .BR termios (3)