126 lines
5.6 KiB
HTML
126 lines
5.6 KiB
HTML
<HTML>
|
|
<HEAD>
|
|
<TITLE>wait(2)</TITLE>
|
|
</HEAD>
|
|
<BODY>
|
|
<H1>wait(2)</H1>
|
|
<HR>
|
|
<PRE>
|
|
|
|
</PRE>
|
|
<H2>NAME</H2><PRE>
|
|
wait, waitpid - wait for process to terminate
|
|
|
|
|
|
</PRE>
|
|
<H2>SYNOPSIS</H2><PRE>
|
|
<STRONG>#include</STRONG> <STRONG><sys/types.h></STRONG>
|
|
<STRONG>#include</STRONG> <STRONG><sys/wait.h></STRONG>
|
|
|
|
<STRONG>pid_t</STRONG> <STRONG>wait(int</STRONG> <STRONG>*</STRONG><EM>status</EM><STRONG>)</STRONG>
|
|
<STRONG>pid_t</STRONG> <STRONG>waitpid(pid_t</STRONG> <EM>pid</EM><STRONG>,</STRONG> <STRONG>int</STRONG> <STRONG>*</STRONG><EM>status</EM><STRONG>,</STRONG> <STRONG>int</STRONG> <EM>options</EM><STRONG>)</STRONG>
|
|
|
|
|
|
</PRE>
|
|
<H2>DESCRIPTION</H2><PRE>
|
|
<STRONG>Wait</STRONG> causes its caller to delay until a signal is received or one of its
|
|
child processes terminates. If any child has died since the last <STRONG>wait</STRONG>,
|
|
return is immediate, returning the process id and exit status of one of
|
|
the terminated children. If there are no children, return is immediate
|
|
with the value -1 returned.
|
|
|
|
On return from a successful <STRONG>wait</STRONG> call, <EM>status</EM> is nonzero, and the high
|
|
byte of <EM>status</EM> contains the low byte of the argument to <STRONG>exit</STRONG> supplied by
|
|
the child process; the low byte of <EM>status</EM> contains the termination status
|
|
of the process. A more precise definition of the <EM>status</EM> word is given in
|
|
<<EM>sys</EM>/<EM>wait</EM>.<EM>h</EM>>. If <STRONG>wait</STRONG> can called with a null pointer argument to
|
|
indicate that no status need be returned.
|
|
|
|
<STRONG>Waitpid</STRONG> provides an alternate interface for programs that must not block
|
|
when collecting the status of child processes, or that wish to wait for
|
|
one particular child. The pid parameter is the process ID of the child
|
|
to wait for, -1 for any child. The <EM>status</EM> parameter is defined as above.
|
|
The <EM>options</EM> parameter is used to indicate the call should not block if
|
|
there are no processes that wish to report status (WNOHANG), and/or that
|
|
children of the current process that are stopped due to a SIGTTIN,
|
|
SIGTTOU, SIGTSTP, or SIGSTOP signal should also have their status
|
|
reported (WUNTRACED). (Job control is not implemented for Minix, but
|
|
these symbold and signals are.)
|
|
|
|
When the WNOHANG option is specified and no processes wish to report
|
|
status, <STRONG>waitpid</STRONG> returns -1 with <STRONG>errno</STRONG> set to <STRONG>EAGAIN</STRONG>. The WNOHANG and
|
|
WUNTRACED options may be combined by <EM>or</EM>'ing the two values.
|
|
|
|
|
|
</PRE>
|
|
<H2>NOTES</H2><PRE>
|
|
The call <STRONG>wait(&</STRONG><EM>status</EM><STRONG>)</STRONG> is equivalent to <STRONG>waitpid(-1,</STRONG> <STRONG>&</STRONG><EM>status</EM><STRONG>,</STRONG> <STRONG>0)</STRONG>.
|
|
|
|
See <STRONG><A HREF="../man2/sigaction.2.html">sigaction(2)</A></STRONG> for a list of termination statuses (signals); 0 status
|
|
indicates normal termination. A special status (0177) is returned for a
|
|
stopped process that has not terminated and can be restarted; see
|
|
<STRONG><A HREF="../man2/ptrace.2.html">ptrace(2)</A></STRONG>. If the 0200 bit of the termination status is set, a core
|
|
image of the process was produced by the system.
|
|
|
|
|
|
|
|
If the parent process terminates without waiting on its children, the
|
|
initialization process (process ID = 1) inherits the children.
|
|
|
|
<<EM>sys</EM>/<EM>wait</EM>.<EM>h</EM>> defines a number of macros that operate on a status word:
|
|
|
|
<STRONG>WIFEXITED(</STRONG><EM>status</EM><STRONG>)</STRONG>
|
|
True if normal exit.
|
|
|
|
<STRONG>WEXITSTATUS(</STRONG><EM>status</EM><STRONG>)</STRONG>
|
|
Exit status if the process returned by a normal exit, zero
|
|
otherwise.
|
|
|
|
<STRONG>WTERMSIG(</STRONG><EM>status</EM><STRONG>)</STRONG>
|
|
Signal number if the process died by a signal, zero otherwise.
|
|
|
|
<STRONG>WIFSIGNALED(</STRONG><EM>status</EM><STRONG>)</STRONG>
|
|
True if the process died by a signal.
|
|
|
|
<STRONG>WIFSTOPPED(</STRONG><EM>status</EM><STRONG>)</STRONG>
|
|
True if the process is stopped. (Never true under Minix.)
|
|
|
|
<STRONG>WSTOPSIG(</STRONG><EM>status</EM><STRONG>)</STRONG>
|
|
Signal number of the signal that stopped the process.
|
|
|
|
|
|
</PRE>
|
|
<H2>RETURN VALUE</H2><PRE>
|
|
If <STRONG>wait</STRONG> returns due to a stopped or terminated child process, the process
|
|
ID of the child is returned to the calling process. Otherwise, a value
|
|
of -1 is returned and <STRONG>errno</STRONG> is set to indicate the error.
|
|
|
|
<STRONG>Waitpid</STRONG> returns -1 if there are no children not previously waited for, if
|
|
the process that it wants to wait for doesn't exist, or if WNOHANG is
|
|
specified and there are no stopped or exited children.
|
|
|
|
|
|
</PRE>
|
|
<H2>ERRORS</H2><PRE>
|
|
<STRONG>Wait</STRONG> will fail and return immediately if one or more of the following are
|
|
true:
|
|
|
|
[ECHILD] The calling process has no existing unwaited-for child
|
|
processes.
|
|
|
|
[EFAULT] The <EM>status</EM> argument points to an illegal address.
|
|
|
|
[EAGAIN] <STRONG>Waitpid</STRONG> is called with the WNOHANG option and no child has
|
|
exited yet.
|
|
|
|
|
|
</PRE>
|
|
<H2>SEE ALSO</H2><PRE>
|
|
<STRONG><A HREF="../man2/execve.2.html">execve(2)</A></STRONG>, <STRONG><A HREF="../man2/exit.2.html">exit(2)</A></STRONG>, <STRONG><A HREF="../man2/sigaction.2.html">sigaction(2)</A></STRONG>.
|
|
|
|
|
|
|
|
</PRE>
|
|
</BODY>
|
|
</HTML>
|