512 lines
27 KiB
HTML
512 lines
27 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<html>
|
|
<head>
|
|
<meta name="generator" content="HTML Tidy, see www.w3.org">
|
|
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
|
<link type="text/css" rel="stylesheet" href="style.css"><!-- Generated by The Open Group's rhtm tool v1.2.1 -->
|
|
<!-- Copyright (c) 2001 The Open Group, All Rights Reserved -->
|
|
<title>wait</title>
|
|
</head>
|
|
<body bgcolor="white">
|
|
<script type="text/javascript" language="JavaScript" src="../jscript/codes.js">
|
|
</script>
|
|
|
|
<basefont size="3"> <a name="wait"></a> <a name="tag_03_822"></a><!-- wait -->
|
|
<!--header start-->
|
|
<center><font size="2">The Open Group Base Specifications Issue 6<br>
|
|
IEEE Std 1003.1-2001<br>
|
|
Copyright © 2001 The IEEE and The Open Group, All Rights reserved.</font></center>
|
|
|
|
<!--header end-->
|
|
<hr size="2" noshade>
|
|
<h4><a name="tag_03_822_01"></a>NAME</h4>
|
|
|
|
<blockquote>wait, waitpid - wait for a child process to stop or terminate</blockquote>
|
|
|
|
<h4><a name="tag_03_822_02"></a>SYNOPSIS</h4>
|
|
|
|
<blockquote class="synopsis">
|
|
<p><code><tt>#include <<a href="../basedefs/sys/wait.h.html">sys/wait.h</a>><br>
|
|
<br>
|
|
pid_t wait(int *</tt><i>stat_loc</i><tt>);<br>
|
|
pid_t waitpid(pid_t</tt> <i>pid</i><tt>, int *</tt><i>stat_loc</i><tt>, int</tt> <i>options</i><tt>);<br>
|
|
</tt></code></p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_822_03"></a>DESCRIPTION</h4>
|
|
|
|
<blockquote>
|
|
<p>The <i>wait</i>() and <i>waitpid</i>() functions shall obtain status information pertaining to one of the caller's child
|
|
processes. Various options permit status information to be obtained for child processes that have terminated or stopped. If status
|
|
information is available for two or more child processes, the order in which their status is reported is unspecified.</p>
|
|
|
|
<p>The <i>wait</i>() function shall suspend execution of the calling thread until status information for one of the terminated
|
|
child processes of the calling process is available, or until delivery of a signal whose action is either to execute a
|
|
signal-catching function or to terminate the process. If more than one thread is suspended in <i>wait</i>() or <i>waitpid</i>()
|
|
awaiting termination of the same process, exactly one thread shall return the process status at the time of the target process
|
|
termination. If status information is available prior to the call to <i>wait</i>(), return shall be immediate.</p>
|
|
|
|
<p>The <i>waitpid</i>() function shall be equivalent to <i>wait</i>() if the <i>pid</i> argument is (<b>pid_t</b>)-1 and the
|
|
<i>options</i> argument is 0. Otherwise, its behavior shall be modified by the values of the <i>pid</i> and <i>options</i>
|
|
arguments.</p>
|
|
|
|
<p>The <i>pid</i> argument specifies a set of child processes for which <i>status</i> is requested. The <i>waitpid</i>() function
|
|
shall only return the status of a child process from this set:</p>
|
|
|
|
<ul>
|
|
<li>
|
|
<p>If <i>pid</i> is equal to (<b>pid_t</b>)-1, <i>status</i> is requested for any child process. In this respect, <i>waitpid</i>()
|
|
is then equivalent to <i>wait</i>().</p>
|
|
</li>
|
|
|
|
<li>
|
|
<p>If <i>pid</i> is greater than 0, it specifies the process ID of a single child process for which <i>status</i> is requested.</p>
|
|
</li>
|
|
|
|
<li>
|
|
<p>If <i>pid</i> is 0, <i>status</i> is requested for any child process whose process group ID is equal to that of the calling
|
|
process.</p>
|
|
</li>
|
|
|
|
<li>
|
|
<p>If <i>pid</i> is less than (<b>pid_t</b>)-1, <i>status</i> is requested for any child process whose process group ID is equal to
|
|
the absolute value of <i>pid</i>.</p>
|
|
</li>
|
|
</ul>
|
|
|
|
<p>The <i>options</i> argument is constructed from the bitwise-inclusive OR of zero or more of the following flags, defined in the
|
|
<a href="../basedefs/sys/wait.h.html"><i><sys/wait.h></i></a> header:</p>
|
|
|
|
<dl compact>
|
|
<dt>WCONTINUED</dt>
|
|
|
|
<dd><sup>[<a href="javascript:open_code('XSI')">XSI</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">
|
|
The <i>waitpid</i>() function shall report the status of any continued child process specified by <i>pid</i> whose status has not
|
|
been reported since it continued from a job control stop. <img src="../images/opt-end.gif" alt="[Option End]" border="0"></dd>
|
|
|
|
<dt>WNOHANG</dt>
|
|
|
|
<dd>The <i>waitpid</i>() function shall not suspend execution of the calling thread if <i>status</i> is not immediately available
|
|
for one of the child processes specified by <i>pid</i>.</dd>
|
|
|
|
<dt>WUNTRACED</dt>
|
|
|
|
<dd>The status of any child processes specified by <i>pid</i> that are stopped, and whose status has not yet been reported since
|
|
they stopped, shall also be reported to the requesting process.</dd>
|
|
</dl>
|
|
|
|
<p><sup>[<a href="javascript:open_code('XSI')">XSI</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">
|
|
If the calling process has SA_NOCLDWAIT set or has SIGCHLD set to SIG_IGN, and the process has no unwaited-for children that were
|
|
transformed into zombie processes, the calling thread shall block until all of the children of the process containing the calling
|
|
thread terminate, and <i>wait</i>() and <i>waitpid</i>() shall fail and set <i>errno</i> to [ECHILD]. <img src=
|
|
"../images/opt-end.gif" alt="[Option End]" border="0"></p>
|
|
|
|
<p>If <i>wait</i>() or <i>waitpid</i>() return because the status of a child process is available, these functions shall return a
|
|
value equal to the process ID of the child process. In this case, if the value of the argument <i>stat_loc</i> is not a null
|
|
pointer, information shall be stored in the location pointed to by <i>stat_loc</i>. The value stored at the location pointed to by
|
|
<i>stat_loc</i> shall be 0 if and only if the status returned is from a terminated child process that terminated by one of the
|
|
following means:</p>
|
|
|
|
<ol>
|
|
<li>
|
|
<p>The process returned 0 from <i>main</i>().</p>
|
|
</li>
|
|
|
|
<li>
|
|
<p>The process called <a href="../functions/_exit.html"><i>_exit</i>()</a> or <a href="../functions/exit.html"><i>exit</i>()</a>
|
|
with a <i>status</i> argument of 0.</p>
|
|
</li>
|
|
|
|
<li>
|
|
<p>The process was terminated because the last thread in the process terminated.</p>
|
|
</li>
|
|
</ol>
|
|
|
|
<p>Regardless of its value, this information may be interpreted using the following macros, which are defined in <a href=
|
|
"../basedefs/sys/wait.h.html"><i><sys/wait.h></i></a> and evaluate to integral expressions; the <i>stat_val</i> argument is
|
|
the integer value pointed to by <i>stat_loc</i>.</p>
|
|
|
|
<dl compact>
|
|
<dt>WIFEXITED(<i>stat_val</i>)</dt>
|
|
|
|
<dd><br>
|
|
Evaluates to a non-zero value if <i>status</i> was returned for a child process that terminated normally.</dd>
|
|
|
|
<dt>WEXITSTATUS(<i>stat_val</i>)</dt>
|
|
|
|
<dd><br>
|
|
If the value of WIFEXITED(<i>stat_val</i>) is non-zero, this macro evaluates to the low-order 8 bits of the <i>status</i> argument
|
|
that the child process passed to <a href="../functions/_exit.html"><i>_exit</i>()</a> or <a href=
|
|
"../functions/exit.html"><i>exit</i>()</a>, or the value the child process returned from <i>main</i>().</dd>
|
|
|
|
<dt>WIFSIGNALED(<i>stat_val</i>)</dt>
|
|
|
|
<dd><br>
|
|
Evaluates to a non-zero value if <i>status</i> was returned for a child process that terminated due to the receipt of a signal that
|
|
was not caught (see <a href="../basedefs/signal.h.html"><i><signal.h></i></a>).</dd>
|
|
|
|
<dt>WTERMSIG(<i>stat_val</i>)</dt>
|
|
|
|
<dd><br>
|
|
If the value of WIFSIGNALED(<i>stat_val</i>) is non-zero, this macro evaluates to the number of the signal that caused the
|
|
termination of the child process.</dd>
|
|
|
|
<dt>WIFSTOPPED(<i>stat_val</i>)</dt>
|
|
|
|
<dd><br>
|
|
Evaluates to a non-zero value if <i>status</i> was returned for a child process that is currently stopped.</dd>
|
|
|
|
<dt>WSTOPSIG(<i>stat_val</i>)</dt>
|
|
|
|
<dd><br>
|
|
If the value of WIFSTOPPED(<i>stat_val</i>) is non-zero, this macro evaluates to the number of the signal that caused the child
|
|
process to stop.</dd>
|
|
|
|
<dt>WIFCONTINUED(<i>stat_val</i>)</dt>
|
|
|
|
<dd><sup>[<a href="javascript:open_code('XSI')">XSI</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border=
|
|
"0"><br>
|
|
Evaluates to a non-zero value if <i>status</i> was returned for a child process that has continued from a job control stop. <img
|
|
src="../images/opt-end.gif" alt="[Option End]" border="0"></dd>
|
|
</dl>
|
|
|
|
<p><sup>[<a href="javascript:open_code('SPN')">SPN</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">
|
|
It is unspecified whether the <i>status</i> value returned by calls to <i>wait</i>() or <i>waitpid</i>() for processes created by
|
|
<a href="../functions/posix_spawn.html"><i>posix_spawn</i>()</a> or <a href=
|
|
"../functions/posix_spawnp.html"><i>posix_spawnp</i>()</a> can indicate a WIFSTOPPED(<i>stat_val</i>) before subsequent calls to
|
|
<i>wait</i>() or <i>waitpid</i>() indicate WIFEXITED(<i>stat_val</i>) as the result of an error detected before the new process
|
|
image starts executing.</p>
|
|
|
|
<p>It is unspecified whether the <i>status</i> value returned by calls to <i>wait</i>() or <i>waitpid</i>() for processes created
|
|
by <a href="../functions/posix_spawn.html"><i>posix_spawn</i>()</a> or <a href=
|
|
"../functions/posix_spawnp.html"><i>posix_spawnp</i>()</a> can indicate a WIFSIGNALED(<i>stat_val</i>) if a signal is sent to the
|
|
parent's process group after <a href="../functions/posix_spawn.html"><i>posix_spawn</i>()</a> or <a href=
|
|
"../functions/posix_spawnp.html"><i>posix_spawnp</i>()</a> is called. <img src="../images/opt-end.gif" alt="[Option End]" border=
|
|
"0"></p>
|
|
|
|
<p>If the information pointed to by <i>stat_loc</i> was stored by a call to <i>waitpid</i>() that specified the WUNTRACED flag
|
|
<sup>[<a href="javascript:open_code('XSI')">XSI</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">
|
|
and did not specify the WCONTINUED flag, <img src="../images/opt-end.gif" alt="[Option End]" border="0"> exactly one of the
|
|
macros WIFEXITED(*<i>stat_loc</i>), WIFSIGNALED(*<i>stat_loc</i>), and WIFSTOPPED(*<i>stat_loc</i>) shall evaluate to a non-zero
|
|
value.</p>
|
|
|
|
<p>If the information pointed to by <i>stat_loc</i> was stored by a call to <i>waitpid</i>() that specified the WUNTRACED <sup>[<a
|
|
href="javascript:open_code('XSI')">XSI</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0"> and
|
|
WCONTINUED <img src="../images/opt-end.gif" alt="[Option End]" border="0"> flags, exactly one of the macros
|
|
WIFEXITED(*<i>stat_loc</i>), WIFSIGNALED(*<i>stat_loc</i>), WIFSTOPPED(*<i>stat_loc</i>), <sup>[<a href=
|
|
"javascript:open_code('XSI')">XSI</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0"> and
|
|
WIFCONTINUED(*<i>stat_loc</i>) <img src="../images/opt-end.gif" alt="[Option End]" border="0"> shall evaluate to a non-zero
|
|
value.</p>
|
|
|
|
<p>If the information pointed to by <i>stat_loc</i> was stored by a call to <i>waitpid</i>() that did not specify the WUNTRACED
|
|
<sup>[<a href="javascript:open_code('XSI')">XSI</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">
|
|
or WCONTINUED <img src="../images/opt-end.gif" alt="[Option End]" border="0"> flags, or by a call to the <i>wait</i>()
|
|
function, exactly one of the macros WIFEXITED(*<i>stat_loc</i>) and WIFSIGNALED(*<i>stat_loc</i>) shall evaluate to a non-zero
|
|
value.</p>
|
|
|
|
<p>If the information pointed to by <i>stat_loc</i> was stored by a call to <i>waitpid</i>() that did not specify the WUNTRACED
|
|
flag <sup>[<a href="javascript:open_code('XSI')">XSI</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">
|
|
and specified the WCONTINUED flag, <img src="../images/opt-end.gif" alt="[Option End]" border="0"> or by a call to the
|
|
<i>wait</i>() function, exactly one of the macros WIFEXITED(*<i>stat_loc</i>), WIFSIGNALED(*<i>stat_loc</i>), <sup>[<a href=
|
|
"javascript:open_code('XSI')">XSI</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0"> and
|
|
WIFCONTINUED(*<i>stat_loc</i>) <img src="../images/opt-end.gif" alt="[Option End]" border="0"> shall evaluate to a non-zero
|
|
value.</p>
|
|
|
|
<p>If _POSIX_REALTIME_SIGNALS is defined, and the implementation queues the SIGCHLD signal, then if <i>wait</i>() or
|
|
<i>waitpid</i>() returns because the status of a child process is available, any pending SIGCHLD signal associated with the process
|
|
ID of the child process shall be discarded. Any other pending SIGCHLD signals shall remain pending.</p>
|
|
|
|
<p>Otherwise, if SIGCHLD is blocked, if <i>wait</i>() or <i>waitpid</i>() return because the status of a child process is
|
|
available, any pending SIGCHLD signal shall be cleared unless the status of another child process is available.</p>
|
|
|
|
<p>For all other conditions, it is unspecified whether child <i>status</i> will be available when a SIGCHLD signal is
|
|
delivered.</p>
|
|
|
|
<p>There may be additional implementation-defined circumstances under which <i>wait</i>() or <i>waitpid</i>() report <i>status</i>.
|
|
This shall not occur unless the calling process or one of its child processes explicitly makes use of a non-standard extension. In
|
|
these cases the interpretation of the reported <i>status</i> is implementation-defined.</p>
|
|
|
|
<p><sup>[<a href="javascript:open_code('XSI')">XSI</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">
|
|
If a parent process terminates without waiting for all of its child processes to terminate, the remaining child processes shall be
|
|
assigned a new parent process ID corresponding to an implementation-defined system process. <img src="../images/opt-end.gif" alt=
|
|
"[Option End]" border="0"></p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_822_04"></a>RETURN VALUE</h4>
|
|
|
|
<blockquote>
|
|
<p>If <i>wait</i>() or <i>waitpid</i>() returns because the status of a child process is available, these functions shall return a
|
|
value equal to the process ID of the child process for which <i>status</i> is reported. If <i>wait</i>() or <i>waitpid</i>()
|
|
returns due to the delivery of a signal to the calling process, -1 shall be returned and <i>errno</i> set to [EINTR]. If
|
|
<i>waitpid</i>() was invoked with WNOHANG set in <i>options</i>, it has at least one child process specified by <i>pid</i> for
|
|
which <i>status</i> is not available, and <i>status</i> is not available for any process specified by <i>pid</i>, 0 is returned.
|
|
Otherwise, (<b>pid_t</b>)-1 shall be returned, and <i>errno</i> set to indicate the error.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_822_05"></a>ERRORS</h4>
|
|
|
|
<blockquote>
|
|
<p>The <i>wait</i>() function shall fail if:</p>
|
|
|
|
<dl compact>
|
|
<dt>[ECHILD]</dt>
|
|
|
|
<dd>The calling process has no existing unwaited-for child processes.</dd>
|
|
|
|
<dt>[EINTR]</dt>
|
|
|
|
<dd>The function was interrupted by a signal. The value of the location pointed to by <i>stat_loc</i> is undefined.</dd>
|
|
</dl>
|
|
|
|
<p>The <i>waitpid</i>() function shall fail if:</p>
|
|
|
|
<dl compact>
|
|
<dt>[ECHILD]</dt>
|
|
|
|
<dd>The process specified by <i>pid</i> does not exist or is not a child of the calling process, or the process group specified by
|
|
<i>pid</i> does not exist or does not have any member process that is a child of the calling process.</dd>
|
|
|
|
<dt>[EINTR]</dt>
|
|
|
|
<dd>The function was interrupted by a signal. The value of the location pointed to by <i>stat_loc</i> is undefined.</dd>
|
|
|
|
<dt>[EINVAL]</dt>
|
|
|
|
<dd>The <i>options</i> argument is not valid.</dd>
|
|
</dl>
|
|
</blockquote>
|
|
|
|
<hr>
|
|
<div class="box"><em>The following sections are informative.</em></div>
|
|
|
|
<h4><a name="tag_03_822_06"></a>EXAMPLES</h4>
|
|
|
|
<blockquote>
|
|
<p>None.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_822_07"></a>APPLICATION USAGE</h4>
|
|
|
|
<blockquote>
|
|
<p>None.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_822_08"></a>RATIONALE</h4>
|
|
|
|
<blockquote>
|
|
<p>A call to the <i>wait</i>() or <i>waitpid</i>() function only returns <i>status</i> on an immediate child process of the calling
|
|
process; that is, a child that was produced by a single <a href="../functions/fork.html"><i>fork</i>()</a> call (perhaps followed
|
|
by an <i><a href="../functions/exec.html">exec</a></i> or other function calls) from the parent. If a child produces grandchildren
|
|
by further use of <a href="../functions/fork.html"><i>fork</i>()</a>, none of those grandchildren nor any of their descendants
|
|
affect the behavior of a <i>wait</i>() from the original parent process. Nothing in this volume of IEEE Std 1003.1-2001
|
|
prevents an implementation from providing extensions that permit a process to get <i>status</i> from a grandchild or any other
|
|
process, but a process that does not use such extensions must be guaranteed to see <i>status</i> from only its direct children.</p>
|
|
|
|
<p>The <i>waitpid</i>() function is provided for three reasons:</p>
|
|
|
|
<ol>
|
|
<li>
|
|
<p>To support job control</p>
|
|
</li>
|
|
|
|
<li>
|
|
<p>To permit a non-blocking version of the <i>wait</i>() function</p>
|
|
</li>
|
|
|
|
<li>
|
|
<p>To permit a library routine, such as <a href="../functions/system.html"><i>system</i>()</a> or <a href=
|
|
"../functions/pclose.html"><i>pclose</i>()</a>, to wait for its children without interfering with other terminated children for
|
|
which the process has not waited</p>
|
|
</li>
|
|
</ol>
|
|
|
|
<p>The first two of these facilities are based on the <i>wait3</i>() function provided by 4.3 BSD. The function uses the
|
|
<i>options</i> argument, which is equivalent to an argument to <i>wait3</i>(). The WUNTRACED flag is used only in conjunction with
|
|
job control on systems supporting job control. Its name comes from 4.3 BSD and refers to the fact that there are two types of
|
|
stopped processes in that implementation: processes being traced via the <i>ptrace</i>() debugging facility and (untraced)
|
|
processes stopped by job control signals. Since <i>ptrace</i>() is not part of this volume of IEEE Std 1003.1-2001, only
|
|
the second type is relevant. The name WUNTRACED was retained because its usage is the same, even though the name is not intuitively
|
|
meaningful in this context.</p>
|
|
|
|
<p>The third reason for the <i>waitpid</i>() function is to permit independent sections of a process to spawn and wait for children
|
|
without interfering with each other. For example, the following problem occurs in developing a portable shell, or command
|
|
interpreter:</p>
|
|
|
|
<pre>
|
|
<tt>stream = popen("/bin/true");
|
|
(void) system("sleep 100");
|
|
(void) pclose(stream);
|
|
</tt>
|
|
</pre>
|
|
|
|
<p>On all historical implementations, the final <a href="../functions/pclose.html"><i>pclose</i>()</a> fails to reap the
|
|
<i>wait</i>() <i>status</i> of the <a href="../functions/popen.html"><i>popen</i>()</a>.</p>
|
|
|
|
<p>The status values are retrieved by macros, rather than given as specific bit encodings as they are in most historical
|
|
implementations (and thus expected by existing programs). This was necessary to eliminate a limitation on the number of signals an
|
|
implementation can support that was inherent in the traditional encodings. This volume of IEEE Std 1003.1-2001 does
|
|
require that a <i>status</i> value of zero corresponds to a process calling <i>_exit</i>(0), as this is the most common encoding
|
|
expected by existing programs. Some of the macro names were adopted from 4.3 BSD.</p>
|
|
|
|
<p>These macros syntactically operate on an arbitrary integer value. The behavior is undefined unless that value is one stored by a
|
|
successful call to <i>wait</i>() or <i>waitpid</i>() in the location pointed to by the <i>stat_loc</i> argument. An early proposal
|
|
attempted to make this clearer by specifying each argument as *<i>stat_loc</i> rather than <i>stat_val</i>. However, that did not
|
|
follow the conventions of other specifications in this volume of IEEE Std 1003.1-2001 or traditional usage. It also could
|
|
have implied that the argument to the macro must literally be *<i>stat_loc</i>; in fact, that value can be stored or passed as an
|
|
argument to other functions before being interpreted by these macros.</p>
|
|
|
|
<p>The extension that affects <i>wait</i>() and <i>waitpid</i>() and is common in historical implementations is the <i>ptrace</i>()
|
|
function. It is called by a child process and causes that child to stop and return a <i>status</i> that appears identical to the
|
|
<i>status</i> indicated by WIFSTOPPED. The <i>status</i> of <i>ptrace</i>() children is traditionally returned regardless of the
|
|
WUNTRACED flag (or by the <i>wait</i>() function). Most applications do not need to concern themselves with such extensions because
|
|
they have control over what extensions they or their children use. However, applications, such as command interpreters, that invoke
|
|
arbitrary processes may see this behavior when those arbitrary processes misuse such extensions.</p>
|
|
|
|
<p>Implementations that support <b>core</b> file creation or other implementation-defined actions on termination of some processes
|
|
traditionally provide a bit in the <i>status</i> returned by <i>wait</i>() to indicate that such actions have occurred.</p>
|
|
|
|
<p>Allowing the <i>wait</i>() family of functions to discard a pending SIGCHLD signal that is associated with a successfully
|
|
waited-for child process puts them into the <a href="../functions/sigwait.html"><i>sigwait</i>()</a> and <a href=
|
|
"../functions/sigwaitinfo.html"><i>sigwaitinfo</i>()</a> category with respect to SIGCHLD.</p>
|
|
|
|
<p>This definition allows implementations to treat a pending SIGCHLD signal as accepted by the process in <i>wait</i>(), with the
|
|
same meaning of "accepted" as when that word is applied to the <a href="../functions/sigwait.html"><i>sigwait</i>()</a> family of
|
|
functions.</p>
|
|
|
|
<p>Allowing the <i>wait</i>() family of functions to behave this way permits an implementation to be able to deal precisely with
|
|
SIGCHLD signals.</p>
|
|
|
|
<p>In particular, an implementation that does accept (discard) the SIGCHLD signal can make the following guarantees regardless of
|
|
the queuing depth of signals in general (the list of waitable children can hold the SIGCHLD queue):</p>
|
|
|
|
<ol>
|
|
<li>
|
|
<p>If a SIGCHLD signal handler is established via <a href="../functions/sigaction.html"><i>sigaction</i>()</a> without the
|
|
SA_RESETHAND flag, SIGCHLD signals can be accurately counted; that is, exactly one SIGCHLD signal will be delivered to or accepted
|
|
by the process for every child process that terminates.</p>
|
|
</li>
|
|
|
|
<li>
|
|
<p>A single <i>wait</i>() issued from a SIGCHLD signal handler can be guaranteed to return immediately with status information for
|
|
a child process.</p>
|
|
</li>
|
|
|
|
<li>
|
|
<p>When SA_SIGINFO is requested, the SIGCHLD signal handler can be guaranteed to receive a non-NULL pointer to a <b>siginfo_t</b>
|
|
structure that describes a child process for which a wait via <i>waitpid</i>() or <a href=
|
|
"../functions/waitid.html"><i>waitid</i>()</a> will not block or fail.</p>
|
|
</li>
|
|
|
|
<li>
|
|
<p>The <a href="../functions/system.html"><i>system</i>()</a> function will not cause a process' SIGCHLD handler to be called as a
|
|
result of the <a href="../functions/fork.html"><i>fork</i>()</a>/ <i><a href="../functions/exec.html">exec</a></i> executed within
|
|
<a href="../functions/system.html"><i>system</i>()</a> because <a href="../functions/system.html"><i>system</i>()</a> will accept
|
|
the SIGCHLD signal when it performs a <i>waitpid</i>() for its child process. This is a desirable behavior of <a href=
|
|
"../functions/system.html"><i>system</i>()</a> so that it can be used in a library without causing side effects to the application
|
|
linked with the library.</p>
|
|
</li>
|
|
</ol>
|
|
|
|
<p>An implementation that does not permit the <i>wait</i>() family of functions to accept (discard) a pending SIGCHLD signal
|
|
associated with a successfully waited-for child, cannot make the guarantees described above for the following reasons:</p>
|
|
|
|
<dl compact>
|
|
<dt>Guarantee #1</dt>
|
|
|
|
<dd><br>
|
|
Although it might be assumed that reliable queuing of all SIGCHLD signals generated by the system can make this guarantee, the
|
|
counter-example is the case of a process that blocks SIGCHLD and performs an indefinite loop of <a href=
|
|
"../functions/fork.html"><i>fork</i>()</a>/ <i>wait</i>() operations. If the implementation supports queued signals, then
|
|
eventually the system will run out of memory for the queue. The guarantee cannot be made because there must be some limit to the
|
|
depth of queuing.</dd>
|
|
|
|
<dt>Guarantees #2 and #3</dt>
|
|
|
|
<dd><br>
|
|
These cannot be guaranteed unless the <i>wait</i>() family of functions accepts the SIGCHLD signal. Otherwise, a <a href=
|
|
"../functions/fork.html"><i>fork</i>()</a>/ <i>wait</i>() executed while SIGCHLD is blocked (as in the <a href=
|
|
"../functions/system.html"><i>system</i>()</a> function) will result in an invocation of the handler when SIGCHLD is unblocked,
|
|
after the process has disappeared.</dd>
|
|
|
|
<dt>Guarantee #4</dt>
|
|
|
|
<dd><br>
|
|
Although possible to make this guarantee, <a href="../functions/system.html"><i>system</i>()</a> would have to set the SIGCHLD
|
|
handler to SIG_DFL so that the SIGCHLD signal generated by its <a href="../functions/fork.html"><i>fork</i>()</a> would be
|
|
discarded (the SIGCHLD default action is to be ignored), then restore it to its previous setting. This would have the undesirable
|
|
side effect of discarding all SIGCHLD signals pending to the process.</dd>
|
|
</dl>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_822_09"></a>FUTURE DIRECTIONS</h4>
|
|
|
|
<blockquote>
|
|
<p>None.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_822_10"></a>SEE ALSO</h4>
|
|
|
|
<blockquote>
|
|
<p><a href="exec.html"><i><a href="../functions/exec.html">exec</a></i>()</a> , <a href="exit.html"><i>exit</i>()</a> , <a href=
|
|
"fork.html"><i>fork</i>()</a> , <a href="waitid.html"><i>waitid</i>()</a> , the Base Definitions volume of
|
|
IEEE Std 1003.1-2001, <a href="../basedefs/signal.h.html"><i><signal.h></i></a>, <a href=
|
|
"../basedefs/sys/wait.h.html"><i><sys/wait.h></i></a></p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_822_11"></a>CHANGE HISTORY</h4>
|
|
|
|
<blockquote>
|
|
<p>First released in Issue 1. Derived from Issue 1 of the SVID.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_822_12"></a>Issue 5</h4>
|
|
|
|
<blockquote>
|
|
<p>The DESCRIPTION is updated for alignment with the POSIX Threads Extension.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_822_13"></a>Issue 6</h4>
|
|
|
|
<blockquote>
|
|
<p>The following new requirements on POSIX implementations derive from alignment with the Single UNIX Specification:</p>
|
|
|
|
<ul>
|
|
<li>
|
|
<p>The requirement to include <a href="../basedefs/sys/types.h.html"><i><sys/types.h></i></a> has been removed. Although <a
|
|
href="../basedefs/sys/types.h.html"><i><sys/types.h></i></a> was required for conforming implementations of previous POSIX
|
|
specifications, it was not required for UNIX applications.</p>
|
|
</li>
|
|
</ul>
|
|
|
|
<p>The following changes were made to align with the IEEE P1003.1a draft standard:</p>
|
|
|
|
<ul>
|
|
<li>
|
|
<p>The processing of the SIGCHLD signal and the [ECHILD] error is clarified.</p>
|
|
</li>
|
|
</ul>
|
|
|
|
<p>The semantics of WIFSTOPPED(<i>stat_val</i>), WIFEXITED(<i>stat_val</i>), and WIFSIGNALED(<i>stat_val</i>) are defined with
|
|
respect to <a href="../functions/posix_spawn.html"><i>posix_spawn</i>()</a> or <a href=
|
|
"../functions/posix_spawnp.html"><i>posix_spawnp</i>()</a> for alignment with IEEE Std 1003.1d-1999.</p>
|
|
|
|
<p>The DESCRIPTION is updated for alignment with the ISO/IEC 9899:1999 standard.</p>
|
|
</blockquote>
|
|
|
|
<div class="box"><em>End of informative text.</em></div>
|
|
|
|
<hr>
|
|
<hr size="2" noshade>
|
|
<center><font size="2"><!--footer start-->
|
|
UNIX ® is a registered Trademark of The Open Group.<br>
|
|
POSIX ® is a registered Trademark of The IEEE.<br>
|
|
[ <a href="../mindex.html">Main Index</a> | <a href="../basedefs/contents.html">XBD</a> | <a href=
|
|
"../utilities/contents.html">XCU</a> | <a href="../functions/contents.html">XSH</a> | <a href="../xrat/contents.html">XRAT</a>
|
|
]</font></center>
|
|
|
|
<!--footer end-->
|
|
<hr size="2" noshade>
|
|
</body>
|
|
</html>
|
|
|