WAIT(2-POSIX) RISC/os Reference Manual WAIT(2-POSIX)
NAME
wait, waitpid - wait for child process to stop or terminate
SYNOPSIS
#include <sys/types.h>
#include <sys/wait.h>
pidt wait(statloc)
int *statloc;
pidt waitpid(pid, statloc, options)
pidt pid;
int *statloc, options;
DESCRIPTION
wait suspends the calling process until one of the immediate
children terminates or until a child that is being traced
stops. If a signal is received and if a child process
stopped or terminated prior to the call on wait, return is
immediate.
waitpid behaves identically to wait if pid is -1 and options
is zero. Otherwise, the behavior of waitpid is modified by
the value of pid and options.
pid specifies a set of child processes for which status is
requested. waitpid will only return the status of a child
from this set.
1. If pid is -1, status is requested for any child process.
(waitpid is then equivalent to wait).
2. If pid is greater than zero, it specifies the process ID
of a single child process for which status is requested.
3. If pid is zero, status is requested for any child process
whose process group ID is equal to that of the calling
process.
4. If pid is less than -1, status is requested for any child
process whose process group ID is equal to the absolute
value of pid .
options is constructed from the bitwise inclusive OR of zero
or more of the following flags (defined in <sys/wait.h>):
WNOHANG waitpid does not suspend execution of
the calling process if status is not
immediately available for one of the
child processes specified by pid.
WUNTRACED The status of any child processes
Printed 1/15/91 Page 1
WAIT(2-POSIX) RISC/os Reference Manual WAIT(2-POSIX)
specified by pid that are stopped, and
whose status has not yet been reported
since they stopped, is also reported to
the calling process.
If wait or waitpid return because the status of a child pro-
cess is available, the return value will be equal to the
process ID of the child process. In this case, if the value
of stat_loc is not NULL, information is stored in the loca-
tion pointed to by stat_loc. If and only if the staus
returned is from a terminated child process that returned a
value of zero from main() or passed a value of zero as the
status argument to _exit() or exit(), the value stored at
this location is zero. Regardless of its value, this infor-
mation may be interpreted using the following macros
(defined in <sys/wait.h>). statval is the integer pointed
to by stat_loc.
WIFEXITED(statval) Evaluates to a non-zero value if
status was returned for a child
process that terminated normally.
WEXITSTATUS(statval) If the value of WIFEXITED(statval)
is non-zero, this macros evaluates
the low-order 8 bits of the status
argument that the child process
returned from main().
WIFSIGNALED(statval) Evaluates to a non-zero value if
status was returned for a child
process that terminated due to the
receipt of a signal that was not
caught.
WTERMSIG(statval) If the value of
WIFSIGNALED(statval) is non-zero,
this macro evaluates to the number
of the signal that caused the ter-
mination of the child process.
WIFSTOPPED(statval) Evaluates to a non-zero value if
status was returned for a child
process that is currently stopped.
WSTOPSIG(statval) If the value of WIFSTOPPED(statval)
is non-zero, this macro evaluates
to the number of the signal that
caused the child process to stop.
If the information stored at the location pointed to by
stat_loc was stored there by a call to waitpid that speci-
fied the WUNTRACED flag, exactly one of the macros
Page 2 Printed 1/15/91
WAIT(2-POSIX) RISC/os Reference Manual WAIT(2-POSIX)
WIFEXITED(*stat_loc), WIFSIGNALED(*stat_loc), and
WIFSTOPPED(*stat_loc) evaluates to a non-zero value. If the
information was stored there by a call to waitpid that did
not specify the WUNTRACED flag or by a call to wait, exactly
one of the macros WIFEXITED(*stat_loc) and
WIFSIGNALED(*stat_loc) evaluates to a non-zero value.
If a parent process terminates without waiting for its child
processes to terminate, the parent process ID of each child
process is set to 1. This means the initialization process
inherits the child processes [see intro(2)].
RETURN VALUES
If wait or waitpid return because the status of a child pro-
cess is available, the function returns a value equal to the
process ID of the child process for which status is
reported. If wait or waitpid return due to the delivery of
a signal to the calling process, -1 is returned and errno is
set to EINTR. If waitpid was invoked with WNOHANG set in
options, there is a least one child process specified by pid
for which status is not available, and status is not avail-
able for any process specified by pid, zero is returned.
Otherwise, a value of -1 is returned and errno is set to
indicate the error.
ERRORS
If any of the following conditions are true, wait returns -1
and sets errno to the corresponding value:
[ECHILD] The calling process has no existing
unwaited-for child processes.
[EINTR] The function was interrupted by a sig-
nal. The value of the location pointed
to by stat_loc is undefined.
If any of the following conditions occur, waitpid returns -1
and sets errno to the corresponding value:
[ECHILD] The process or process group specified
by pid does not exist or is not a child
of the calling process.
[EINTR] The function was interrupted by a sig-
nal. The value of the location pointed
to by stat_loc is undefined.
[EINVAL] The value of options is not valid.
SEE ALSO
exec(2), exit(2), fork(2), intro(2), pause(2), ptrace(2),
signal(2).
Printed 1/15/91 Page 3
WAIT(2-POSIX) RISC/os Reference Manual WAIT(2-POSIX)
WARNING
wait fails and its actions are undefined if stat_loc points
to an invalid address.
See NOTES in signal(2).
Page 4 Printed 1/15/91