ioctl_tty.2: Update DTR example
[man-pages.git] / man2 / _exit.2
blob6d9067eb6e6a56b408d7b479e0e93e7f5f4c8a92
1 .\" This manpage is Copyright (C) 1992 Drew Eckhardt;
2 .\"             and Copyright (C) 1993 Michael Haardt, Ian Jackson.
3 .\"
4 .\" %%%LICENSE_START(VERBATIM)
5 .\" Permission is granted to make and distribute verbatim copies of this
6 .\" manual provided the copyright notice and this permission notice are
7 .\" preserved on all copies.
8 .\"
9 .\" Permission is granted to copy and distribute modified versions of this
10 .\" manual under the conditions for verbatim copying, provided that the
11 .\" entire resulting derived work is distributed under the terms of a
12 .\" permission notice identical to this one.
13 .\"
14 .\" Since the Linux kernel and libraries are constantly changing, this
15 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
16 .\" responsibility for errors or omissions, or for damages resulting from
17 .\" the use of the information contained herein.  The author(s) may not
18 .\" have taken the same level of care in the production of this manual,
19 .\" which is licensed free of charge, as they might when working
20 .\" professionally.
21 .\"
22 .\" Formatted or processed versions of this manual, if unaccompanied by
23 .\" the source, must acknowledge the copyright and authors of this work.
24 .\" %%%LICENSE_END
25 .\"
26 .\" Modified Wed Jul 21 23:02:38 1993 by Rik Faith <faith@cs.unc.edu>
27 .\" Modified 2001-11-17, aeb
28 .\"
29 .TH _EXIT 2 2021-03-22 "Linux" "Linux Programmer's Manual"
30 .SH NAME
31 _exit, _Exit \- terminate the calling process
32 .SH SYNOPSIS
33 .nf
34 .B #include <unistd.h>
35 .PP
36 .BI "noreturn void _exit(int " status );
37 .PP
38 .B #include <stdlib.h>
39 .PP
40 .BI "noreturn void _Exit(int " status );
41 .fi
42 .PP
43 .RS -4
44 Feature Test Macro Requirements for glibc (see
45 .BR feature_test_macros (7)):
46 .RE
47 .PP
48 .BR _Exit ():
49 .nf
50     _ISOC99_SOURCE || _POSIX_C_SOURCE >= 200112L
51 .fi
52 .SH DESCRIPTION
53 .BR _exit ()
54 terminates the calling process "immediately".
55 Any open file descriptors belonging to the process are closed.
56 Any children of the process are inherited by
57 .BR init (1)
58 (or by the nearest "subreaper" process as defined through the use of the
59 .BR prctl (2)
60 .B PR_SET_CHILD_SUBREAPER
61 operation).
62 The process's parent is sent a
63 .B SIGCHLD
64 signal.
65 .PP
66 The value
67 .I "status & 0xFF"
68 is returned to the parent process as the process's exit status, and
69 can be collected by the parent using one of the
70 .BR wait (2)
71 family of calls.
72 .PP
73 The function
74 .BR _Exit ()
75 is equivalent to
76 .BR _exit ().
77 .SH RETURN VALUE
78 These functions do not return.
79 .SH CONFORMING TO
80 POSIX.1-2001, POSIX.1-2008, SVr4, 4.3BSD.
81 The function
82 .BR _Exit ()
83 was introduced by C99.
84 .SH NOTES
85 For a discussion on the effects of an exit, the transmission of
86 exit status, zombie processes, signals sent, and so on, see
87 .BR exit (3).
88 .PP
89 The function
90 .BR _exit ()
91 is like
92 .BR exit (3),
93 but does not call any
94 functions registered with
95 .BR atexit (3)
97 .BR on_exit (3).
98 Open
99 .BR stdio (3)
100 streams are not flushed.
101 On the other hand,
102 .BR _exit ()
103 does close open file descriptors, and this may cause an unknown delay,
104 waiting for pending output to finish.
105 If the delay is undesired,
106 it may be useful to call functions like
107 .BR tcflush (3)
108 before calling
109 .BR _exit ().
110 Whether any pending I/O is canceled, and which pending I/O may be
111 canceled upon
112 .BR _exit (),
113 is implementation-dependent.
114 .SS C library/kernel differences
115 In glibc up to version 2.3, the
116 .BR _exit ()
117 wrapper function invoked the kernel system call of the same name.
118 Since glibc 2.3, the wrapper function invokes
119 .BR exit_group (2),
120 in order to terminate all of the threads in a process.
122 The raw
123 .BR _exit ()
124 system call terminates only the calling thread, and actions such as
125 reparenting child processes or sending
126 .B SIGCHLD
127 to the parent process are performed only if this is
128 the last thread in the thread group.
129 .\" _exit() is used by pthread_exit() to terminate the calling thread
130 .SH SEE ALSO
131 .BR execve (2),
132 .BR exit_group (2),
133 .BR fork (2),
134 .BR kill (2),
135 .BR wait (2),
136 .BR wait4 (2),
137 .BR waitpid (2),
138 .BR atexit (3),
139 .BR exit (3),
140 .BR on_exit (3),
141 .BR termios (3)