2 .\" Copyright 1989 AT&T. Copyright (c) 2004, Sun Microsystems, Inc. All Rights Reserved. Portions Copyright (c) 1992, X/Open Company Limited. All Rights Reserved.
3 .\" 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
4 .\" http://www.opengroup.org/bookstore/.
5 .\" 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.
6 .\" This notice shall appear on any product containing this material.
7 .\" 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.
8 .\" 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.
9 .\" 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]
10 .TH WAIT 3C "Jun 9, 2004"
12 wait \- wait for child process to stop or terminate
16 #include <sys/types.h>
19 \fBpid_t\fR \fBwait\fR(\fBint *\fR\fIstat_loc\fR);
25 The \fBwait()\fR function will suspend execution of the calling thread until
26 status information for one of its terminated child processes is available, or
27 until delivery of a signal whose action is either to execute a signal-catching
28 function or to terminate the process. If more than one thread is suspended in
29 \fBwait()\fR, \fBwaitpid\fR(3C), or \fBwaitid\fR(2) awaiting termination of the
30 same process, exactly one thread will return the process status at the time of
31 the target process termination. If status information is available prior to the
32 call to \fBwait()\fR, return will be immediate.
35 If \fBwait()\fR returns because the status of a child process is available, it
36 returns the process \fBID\fR of the child process. If the calling process
37 specified a non-zero value for \fIstat_loc\fR, the status of the child process
38 is stored in the location pointed to by \fIstat_loc\fR. That status can be
39 evaluated with the macros described on the \fBwait.h\fR(3HEAD) manual page.
42 In the following, \fIstatus\fR is the object pointed to by \fIstat_loc\fR:
47 If the child process terminated due to an \fB_exit()\fR call, the low order 8
48 bits of \fIstatus\fR will be 0 and the high order 8 bits will contain the low
49 order 7 bits of the argument that the child process passed to \fB_exit()\fR;
56 If the child process terminated due to a signal, the high order 8 bits of
57 \fIstatus\fR will be 0 and the low order 7bits will contain the number of the
58 signal that caused the termination. In addition, if \fBWCOREFLG\fR is set, a
59 "core image" will have been produced; see \fBsignal.h\fR(3HEAD) and
64 One instance of a \fBSIGCHLD\fR signal is queued for each child process whose
65 status has changed. If \fBwait()\fR returns because the status of a child
66 process is available, any pending \fBSIGCHLD\fR signal associated with the
67 process ID of that child process is discarded. Any other pending \fBSIGCHLD\fR
68 signals remain pending.
71 If the calling process has \fBSA_NOCLDWAIT\fR set or has \fBSIGCHLD\fR set to
72 \fBSIG_IGN\fR, and the process has no unwaited children that were transformed
73 into zombie processes, it will block until all of its children terminate, and
74 \fBwait()\fR will fail and set \fBerrno\fR to \fBECHILD\fR.
77 If a parent process terminates without waiting for its child processes to
78 terminate, the parent process \fBID\fR of each child process is set to 1, with
79 the initialization process inheriting the child processes; see \fBIntro\fR(2).
83 When \fBwait()\fR returns due to a terminated child process, the process
84 \fBID\fR of the child is returned to the calling process. Otherwise,
85 \fB\(mi1\fR is returned and \fBerrno\fR is set to indicate the error.
89 The \fBwait()\fR function will fail if:
96 The calling process has no existing unwaited-for child processes.
105 The function was interrupted by a signal.
111 Since \fBwait()\fR blocks on a stopped child, a calling process wanting to see
112 the return results of such a call should use \fBwaitpid\fR(3C) or
113 \fBwaitid\fR(2) instead of \fBwait()\fR. The \fBwait()\fR function is
114 implemented as a call to \fBwaitpid(-1, stat_loc, 0)\fR.
118 See \fBattributes\fR(5) for descriptions of the following attributes:
126 ATTRIBUTE TYPE ATTRIBUTE VALUE
128 Interface Stability Standard
130 MT-Level Async-Signal-Safe
136 \fBIntro\fR(2), \fBexec\fR(2), \fBexit\fR(2), \fBfork\fR(2), \fBpause\fR(2),
137 \fBwaitid\fR(2), \fBptrace\fR(3C), \fBsignal\fR(3C), \fBsignal.h\fR(3HEAD),
138 \fBwaitpid\fR(3C), \fBwait.h\fR(3HEAD), \fBattributes\fR(5)