blob: 026175ab04390ddc4e316c9a9ffe108161ca0e2c [file] [log] [blame]
<html lang="en">
<head>
<title>Termination Internals - The GNU C Library</title>
<meta http-equiv="Content-Type" content="text/html">
<meta name="description" content="The GNU C Library">
<meta name="generator" content="makeinfo 4.13">
<link title="Top" rel="start" href="index.html#Top">
<link rel="up" href="Program-Termination.html#Program-Termination" title="Program Termination">
<link rel="prev" href="Aborting-a-Program.html#Aborting-a-Program" title="Aborting a Program">
<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
<!--
This file documents the GNU C library.
This is Edition 0.12, last updated 2007-10-27,
of `The GNU C Library Reference Manual', for version
2.8 (Sourcery G++ Lite 2011.03-41).
Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2001, 2002,
2003, 2007, 2008, 2010 Free Software Foundation, Inc.
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
any later version published by the Free Software Foundation; with the
Invariant Sections being ``Free Software Needs Free Documentation''
and ``GNU Lesser General Public License'', the Front-Cover texts being
``A GNU Manual'', and with the Back-Cover Texts as in (a) below. A
copy of the license is included in the section entitled "GNU Free
Documentation License".
(a) The FSF's Back-Cover Text is: ``You have the freedom to
copy and modify this GNU manual. Buying copies from the FSF
supports it in developing GNU and promoting software freedom.''-->
<meta http-equiv="Content-Style-Type" content="text/css">
<style type="text/css"><!--
pre.display { font-family:inherit }
pre.format { font-family:inherit }
pre.smalldisplay { font-family:inherit; font-size:smaller }
pre.smallformat { font-family:inherit; font-size:smaller }
pre.smallexample { font-size:smaller }
pre.smalllisp { font-size:smaller }
span.sc { font-variant:small-caps }
span.roman { font-family:serif; font-weight:normal; }
span.sansserif { font-family:sans-serif; font-weight:normal; }
--></style>
<link rel="stylesheet" type="text/css" href="../cs.css">
</head>
<body>
<div class="node">
<a name="Termination-Internals"></a>
<p>
Previous:&nbsp;<a rel="previous" accesskey="p" href="Aborting-a-Program.html#Aborting-a-Program">Aborting a Program</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="Program-Termination.html#Program-Termination">Program Termination</a>
<hr>
</div>
<h4 class="subsection">25.6.5 Termination Internals</h4>
<p>The <code>_exit</code> function is the primitive used for process termination
by <code>exit</code>. It is declared in the header file <samp><span class="file">unistd.h</span></samp>.
<a name="index-unistd_002eh-3144"></a>
<!-- unistd.h -->
<!-- POSIX.1 -->
<div class="defun">
&mdash; Function: void <b>_exit</b> (<var>int status</var>)<var><a name="index-g_t_005fexit-3145"></a></var><br>
<blockquote><p>The <code>_exit</code> function is the primitive for causing a process to
terminate with status <var>status</var>. Calling this function does not
execute cleanup functions registered with <code>atexit</code> or
<code>on_exit</code>.
</p></blockquote></div>
<!-- stdlib.h -->
<!-- ISO -->
<div class="defun">
&mdash; Function: void <b>_Exit</b> (<var>int status</var>)<var><a name="index-g_t_005fExit-3146"></a></var><br>
<blockquote><p>The <code>_Exit</code> function is the ISO&nbsp;C<!-- /@w --> equivalent to <code>_exit</code>.
The ISO&nbsp;C<!-- /@w --> committee members were not sure whether the definitions of
<code>_exit</code> and <code>_Exit</code> were compatible so they have not used the
POSIX name.
<p>This function was introduced in ISO&nbsp;C99<!-- /@w --> and is declared in
<samp><span class="file">stdlib.h</span></samp>.
</p></blockquote></div>
<p>When a process terminates for any reason&mdash;either because the program
terminates, or as a result of a signal&mdash;the
following things happen:
<ul>
<li>All open file descriptors in the process are closed. See <a href="Low_002dLevel-I_002fO.html#Low_002dLevel-I_002fO">Low-Level I/O</a>.
Note that streams are not flushed automatically when the process
terminates; see <a href="I_002fO-on-Streams.html#I_002fO-on-Streams">I/O on Streams</a>.
<li>A process exit status is saved to be reported back to the parent process
via <code>wait</code> or <code>waitpid</code>; see <a href="Process-Completion.html#Process-Completion">Process Completion</a>. If the
program exited, this status includes as its low-order 8 bits the program
exit status.
<li>Any child processes of the process being terminated are assigned a new
parent process. (On most systems, including GNU, this is the <code>init</code>
process, with process ID 1.)
<li>A <code>SIGCHLD</code> signal is sent to the parent process.
<li>If the process is a session leader that has a controlling terminal, then
a <code>SIGHUP</code> signal is sent to each process in the foreground job,
and the controlling terminal is disassociated from that session.
See <a href="Job-Control.html#Job-Control">Job Control</a>.
<li>If termination of a process causes a process group to become orphaned,
and any member of that process group is stopped, then a <code>SIGHUP</code>
signal and a <code>SIGCONT</code> signal are sent to each process in the
group. See <a href="Job-Control.html#Job-Control">Job Control</a>.
</ul>
</body></html>