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