⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wait.html

📁 IEEE 1003.1-2003, Single Unix Specification v3
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<!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-2003 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, 2003 Edition<br>Copyright &copy; 2001-2003 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 &lt;<a href="../basedefs/sys/wait.h.html">sys/wait.h</a>&gt;<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 childprocesses. Various options permit status information to be obtained for child processes that have terminated or stopped. If statusinformation 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 terminatedchild processes of the calling process is available, or until delivery of a signal whose action is either to execute asignal-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 processtermination. 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>() functionshall 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 callingprocess.</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 tothe 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>&lt;sys/wait.h&gt;</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 notbeen 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 availablefor 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 sincethey 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 weretransformed into zombie processes, the calling thread shall block until all of the children of the process containing the callingthread 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 avalue 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 nullpointer, 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 thefollowing 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>&lt;sys/wait.h&gt;</i></a> and evaluate to integral expressions; the <i>stat_val</i> argument isthe 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> argumentthat 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 thatwas not caught (see <a href="../basedefs/signal.h.html"><i>&lt;signal.h&gt;</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 thetermination 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 childprocess 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. <imgsrc="../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 processimage 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 createdby <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 theparent'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">&nbsp;and did not specify the WCONTINUED flag, <img src="../images/opt-end.gif" alt="[Option End]" border="0"> exactly one of themacros WIFEXITED(*<i>stat_loc</i>), WIFSIGNALED(*<i>stat_loc</i>), and WIFSTOPPED(*<i>stat_loc</i>) shall evaluate to a non-zerovalue.</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>[<ahref="javascript:open_code('XSI')">XSI</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0"> &nbsp;andWCONTINUED <img src="../images/opt-end.gif" alt="[Option End]" border="0"> flags, exactly one of the macrosWIFEXITED(*<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"> &nbsp;andWIFCONTINUED(*<i>stat_loc</i>) <img src="../images/opt-end.gif" alt="[Option End]" border="0"> shall evaluate to a non-zerovalue.</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">&nbsp;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-zerovalue.</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 WUNTRACEDflag <sup>[<a href="javascript:open_code('XSI')">XSI</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">&nbsp;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"> &nbsp;andWIFCONTINUED(*<i>stat_loc</i>) <img src="../images/opt-end.gif" alt="[Option End]" border="0"> shall evaluate to a non-zerovalue.</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 processID 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 isavailable, 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 isdelivered.</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. Inthese 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 beassigned 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 avalue 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> forwhich <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>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -