wait
Purpose
Waits for a child process to stop or terminate.
Syntax
int wait (stat_loc) int wait ((int *) 0)
int *stat_loc;
Description
The wait system call suspends the calling process until
it receives a signal that is to be caught, or until any
one of the calling process's child processes stops in a
trace mode or terminates. The wait system call returns
without waiting if a child process that has not been
waited for has already stopped or terminated prior to the
call.
If the stat_loc parameter is nonzero, 16 bits of informa-
tion called status are stored in the low-order 16 bits of
the location pointed to by stat_loc. The status informa-
tion can be used to differentiate between stopped and
terminated child processes and, if the child process ter-
minated, the status information identifies the cause of
termination and passes information to the parent process.
This is accomplished in the following manner:
o If the child process stopped in a trace mode, then
the high-order 8 bits of status contain the number of
the signal that caused the process to stop and the
low-order 8 bits are set to one of the following:
- 0177 (0x7F), which indicates the process was
stopped while being traced. If multi-process
debugging mode was not set by the ptrace system
call, the low-order bits are set to this value.
(For more information on multi-process debugging,
see "ptrace.")
- 0176 (0x7E), which means the process was stopped
after a fork system call. Both the traced
process and its newly forked child process are
stopped. This value only occurs when multi-
process debugging mode is set with the ptrace
system call.
- 0175 (0x7D), which indicates that the process was
stopped after an exec system call. This value
only occurs when multi-process debugging mode is
set with the ptrace system call.
o If the child process terminated due to an exit system
call, the low-order 8 bits of status are 0 and the
high-order 8 bits contain the low-order 8 bits of the
parameter that the child passed to the exit system
call.
o If the child process terminated due to a signal, the
high-order 8 bits of status are 0 and the low-order 8
bits contain the number of the signal that caused the
termination. In addition, if the low-order seventh
bit (bit 0200 or 0x80) is set, then a memory image
file is produced before wait returns.
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 initial-
ization process inherits the child processes.
Note: The effect of the wait system call is modified by
the signal action of the SIGCLD signal. See "Special
Signals" for details.
Warning: The actions of the wait system call are unde-
fined if the stat_loc parameter &pointsout..
Return Value
If the wait system call returns due to a stopped or ter-
minated child process, the process ID of the child is
returned to the calling process. If the wait system call
fails, a value of -1 is returned and errno is set to
indicate the error.
Diagnostics
The wait system call fails and returns without waiting if
one or more of the following are true:
ECHILD The calling process has no existing child
processes not yet waited for.
EINTR The wait system call received a signal.
Related Information
In this book: "exec: execl, execv, execle, execve,
execlp, execvp," "exit, _exit," "fork," "pause,"
"ptrace," "signal," "wait3."