source: trunk/minix/man/man2/wait.2@ 20

Last change on this file since 20 was 9, checked in by Mattia Monga, 14 years ago

Minix 3.1.2a

File size: 4.4 KB
Line 
1.\" Copyright (c) 1980 Regents of the University of California.
2.\" All rights reserved. The Berkeley software License Agreement
3.\" specifies the terms and conditions for redistribution.
4.\"
5.\" @(#)wait.2 6.2 (Berkeley) 6/30/85
6.\"
7.TH WAIT 2 "June 30, 1985"
8.UC 4
9.SH NAME
10wait, waitpid \- wait for process to terminate
11.SH SYNOPSIS
12.ft B
13.nf
14#include <sys/types.h>
15#include <sys/wait.h>
16
17pid_t wait(int *\fIstatus\fP)
18pid_t waitpid(pid_t \fIpid\fP, int *\fIstatus\fP, int \fIoptions\fP)
19.fi
20.SH DESCRIPTION
21.B Wait
22causes its caller to delay until a signal is received or
23one of its child
24processes terminates.
25If any child has died since the last
26.BR wait ,
27return is immediate, returning the process id and
28exit status of one of the terminated
29children.
30If there are no children, return is immediate with
31the value \-1 returned.
32.PP
33On return from a successful
34.B wait
35call,
36.I status
37is nonzero, and the high byte of
38.I status
39contains the low byte of the argument to
40.B exit
41supplied by the child process;
42the low byte of
43.I status
44contains the termination status of the process.
45A more precise definition of the
46.I status
47word is given in
48.RI < sys/wait.h >.
49.B Wait
50can be called with a null pointer argument to indicate that no status need
51be returned.
52.PP
53.B Waitpid
54provides an alternate interface for programs
55that must not block when collecting the status
56of child processes, or that wish to wait for
57one particular child. The pid parameter is
58the process ID of the child to wait for, \-1
59for any child. The
60.I status
61parameter is defined as above. The
62.I options
63parameter is used to indicate the call should not block if
64there are no processes that wish to report status (WNOHANG),
65and/or that children of the current process that are stopped
66due to a SIGTTIN, SIGTTOU, SIGTSTP, or SIGSTOP signal should also have
67their status reported (WUNTRACED). (Job control is not implemented for
68MINIX 3, but these symbols and signals are.)
69.PP
70When the WNOHANG option is specified and no processes
71wish to report status,
72.B waitpid
73either returns 0 under some implementations, or \-1 with
74.B errno
75set to
76.B EAGAIN
77under others.
78(Under MINIX 3 it returns 0.)
79The WNOHANG and WUNTRACED options may be combined by
80.IR or 'ing
81the two values.
82.SH NOTES
83The call
84.BI "wait(&" status ")"
85is equivalent to
86.BI "waitpid(\-1, &" status ", 0)\fR."
87.PP
88See
89.BR sigaction (2)
90for a list of termination statuses (signals);
910 status indicates normal termination.
92A special status (0177) is returned for a stopped process
93that has not terminated and can be restarted;
94see
95.BR ptrace (2).
96If the 0200 bit of the termination status
97is set,
98a core image of the process was produced
99by the system.
100.PP
101If the parent process terminates without
102waiting on its children,
103the initialization process
104(process ID = 1)
105inherits the children.
106.PP
107.I <sys/wait.h>
108defines a number of macros that operate on a status word:
109.TP 5
110.BI "WIFEXITED(" status ")"
111True if normal exit.
112.TP 5
113.BI "WEXITSTATUS(" status ")"
114Exit status if the process returned by a normal exit, zero otherwise.
115.TP 5
116.BI "WTERMSIG(" status ")"
117Signal number if the process died by a signal, zero otherwise.
118.TP 5
119.BI "WIFSIGNALED(" status ")"
120True if the process died by a signal.
121.TP 5
122.BI "WIFSTOPPED(" status ")"
123True if the process is stopped. (Never true under MINIX 3.)
124.TP 5
125.BI "WSTOPSIG(" status ")"
126Signal number of the signal that stopped the process.
127.SH "RETURN VALUE
128If \fBwait\fP returns due to a stopped
129or terminated child process, the process ID of the child
130is returned to the calling process. Otherwise, a value of \-1
131is returned and \fBerrno\fP is set to indicate the error.
132.PP
133.B Waitpid
134returns \-1 if there are no children not previously waited for or if
135the process that it wants to wait for doesn't exist.
136.PP
137.B Waitpid
138returns 0 if WNOHANG is specified and there are no stopped or exited
139children. (Under other implementations it may return \-1 instead. Portable
140code should test for both possibilities.)
141.SH ERRORS
142.B Wait
143will fail and return immediately if one or more of the following
144are true:
145.TP 15
146[ECHILD]
147The calling process has no existing unwaited-for
148child processes.
149.TP 15
150[EFAULT]
151The \fIstatus\fP argument points to an illegal address.
152.TP 15
153[EAGAIN]
154.B Waitpid
155is called with the WNOHANG option and no child has exited yet. (Not under
156MINIX 3, it'll return 0 in this case and leave
157.B errno
158alone.)
159.SH "SEE ALSO"
160.BR execve (2),
161.BR exit (2),
162.BR sigaction (2).
Note: See TracBrowser for help on using the repository browser.