2 .\" Copyright (c) 2007, Sun Microsystems, Inc. All Rights Reserved.
3 .\" Copyright 1989 AT&T
4 .\" Portions Copyright (c) 1992, X/Open Company Limited. All Rights Reserved.
5 .\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for permission to reproduce portions of its copyrighted documentation. Original documentation from The Open Group can be obtained online at
6 .\" http://www.opengroup.org/bookstore/.
7 .\" The Institute of Electrical and Electronics Engineers and The Open Group, have given us permission to reprint portions of their documentation. In the following statement, the phrase "this text" refers to portions of the system documentation. Portions of this text are reprinted and reproduced in electronic form in the Sun OS Reference Manual, from IEEE Std 1003.1, 2004 Edition, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 6, Copyright (C) 2001-2004 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between these versions and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html.
8 .\" This notice shall appear on any product containing this material.
9 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License.
10 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. See the License for the specific language governing permissions and limitations under the License.
11 .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
12 .TH WAITPID 3C "Dec 7, 2007"
14 waitpid \- wait for child process to change state
18 #include <sys/types.h>
21 \fBpid_t\fR \fBwaitpid\fR(\fBpid_t\fR \fIpid\fR, \fBint *\fR\fIstat_loc\fR, \fBint\fR \fIoptions\fR);
27 The \fBwaitpid()\fR function will suspend execution of the calling thread until
28 status information for one of its terminated child processes is available, or
29 until delivery of a signal whose action is either to execute a signal-catching
30 function or to terminate the process. If more than one thread is suspended in
31 \fBwaitpid()\fR, \fBwait\fR(3C), or \fBwaitid\fR(2) awaiting termination of the
32 same process, exactly one thread will return the process status at the time of
33 the target process termination. If status information is available prior to the
34 call to \fBwaitpid()\fR, return will be immediate.
37 The \fIpid\fR argument specifies a set of child processes for which status is
38 requested, as follows:
43 If \fIpid\fR is less than \fB(pid_t)\(mi1\fR, status is requested for any child
44 process whose process group \fBID\fR is equal to the absolute value of
51 If \fIpid\fR is equal to \fB(pid_t)\(mi1\fR, status is requested for any child
58 If \fIpid\fR is equal to \fB(pid_t)0\fR status is requested for any child
59 process whose process group \fBID\fR is equal to that of the calling process.
65 If \fIpid\fR is greater than \fB(pid_t)0\fR, it specifies the process \fBID\fR
66 of the child process for which status is requested.
70 One instance of a \fBSIGCHLD\fR signal is queued for each child process whose
71 status has changed. If \fBwaitpid()\fR returns because the status of a child
72 process is available, and \fBWNOWAIT\fR was not specified in \fIoptions\fR, any
73 pending \fBSIGCHLD\fR signal associated with the process ID of that child
74 process is discarded. Any other pending \fBSIGCHLD\fR signals remain pending.
77 If the calling process has \fBSA_NOCLDWAIT\fR set or has \fBSIGCHLD\fR set to
78 \fBSIG_IGN\fR and the process has no unwaited children that were transformed
79 into zombie processes, it will block until all of its children terminate, and
80 \fBwaitpid()\fR will fail and set \fBerrno\fR to \fBECHILD\fR.
83 If \fBwaitpid()\fR returns because the status of a child process is available,
84 then that status may be evaluated with the macros defined by
85 \fBwait.h\fR(3HEAD) If the calling process had specified a non-zero value of
86 \fIstat_loc\fR, the status of the child process will be stored in the location
87 pointed to by \fIstat_loc\fR.
90 The \fIoptions\fR argument is constructed from the bitwise-inclusive OR of zero
91 or more of the following flags, defined in the header <\fBsys/wait.h\fR>:
95 \fB\fBWCONTINUED\fR\fR
98 The status of any continued child process specified by \fIpid\fR, whose status
99 has not been reported since it continued, is also reported to the calling
109 The \fBwaitpid()\fR function will not suspend execution of the calling process
110 if status is not immediately available for one of the child processes specified
120 Keep the process whose status is returned in \fIstat_loc\fR in a waitable
121 state. The process may be waited for again with identical results.
127 \fB\fBWUNTRACED\fR\fR
130 The status of any child processes specified by \fIpid\fR that are stopped, and
131 whose status has not yet been reported since they stopped, is also reported to
132 the calling process. \fBWSTOPPED\fR is a synonym for \fBWUNTRACED\fR.
138 If \fBwaitpid()\fR returns because the status of a child process is available,
139 it returns a value equal to the process \fBID\fR of the child process for which
140 status is reported. If \fBwaitpid()\fR returns due to the delivery of a signal
141 to the calling process, \fB\(mi1\fR is returned and \fBerrno\fR is set to
142 \fBEINTR\fR. If \fBwaitpid()\fR was invoked with \fBWNOHANG\fR set in
143 \fIoptions\fR, it has at least one child process specified by \fIpid\fR for
144 which status is not available, and status is not available for any process
145 specified by \fIpid\fR, then \fB0\fR is returned. Otherwise, \fB\(mi1\fR is
146 returned and \fBerrno\fR is set to indicate the error.
150 The \fBwaitpid()\fR function will fail if:
157 The process or process group specified by \fIpid\fR does not exist or is not a
158 child of the calling process or can never be in the states specified by
168 The \fBwaitpid()\fR function was interrupted due to the receipt of a signal
169 sent by the calling process.
178 An invalid value was specified for \fIoptions.\fR
184 With \fIoptions\fR equal to \fB0\fR and \fIpid\fR equal to \fB(pid_t)\(mi1\fR,
185 \fBwaitpid()\fR is identical to \fBwait\fR(3C). The \fBwaitpid()\fR function is
186 implemented as a call to the more general \fBwaitid\fR(2) function.
190 See \fBattributes\fR(5) for descriptions of the following attributes:
198 ATTRIBUTE TYPE ATTRIBUTE VALUE
200 Interface Stability Committed
202 MT-Level Async-Signal-Safe
204 Standard See \fBstandards\fR(5).
210 \fBIntro\fR(2), \fBexec\fR(2), \fBexit\fR(2), \fBfork\fR(2), \fBpause\fR(2),
211 \fBsigaction\fR(2), \fBptrace\fR(3C), \fBsignal\fR(3C), \fBsiginfo.h\fR(3HEAD),
212 \fBwait\fR(3C), \fBwait.h\fR(3HEAD), \fBattributes\fR(5), \fBstandards\fR(5)