WAIT2(2J)
NAME
wait2 − wait for process to terminate
SYNOPSIS
#include <wait.h>
wait2(&w.w_status, options)
union wait w;
int options;
cc ... −ljobs
DESCRIPTION
Wait2 is similar to the standard wait(2) system call, but allow additional options useful with job control. They return the process ID of a terminated or stopped child process. The w.w_status and option words are described by definitions and macros in the file <wait.h>; the union and its bitfield definitions and associated macros given there provide convenient and mnemonic access to the word of status returned by a wait2 call. If the call returns a process ID, several macros are available to interpret the status word returned. If the process is stopped, WIFSTOPPED(w) is true, and the signal that caused it to stop is w.w_stopsig. If the process is not stopped (has terminated), WIFEXITED(w) determines whether it terminated by calling exit(2); if so, the exit code is w.w_retcode. WIFSIGNALED(w) is true if the process was terminated by a signal (see signal(2)); the signal causing termination was w.w_termsig, and w.w_coredump indicates whether a core dump was produced.
There are two options, which may be combined by oring them together. The first is WNOHANG which causes the wait2 to not hang if there are no processes which wish to report status, rather returning a pid of 0 in this case as the result of the wait2. The second option is WUNTRACED which causes wait2 to return information when children of the current process which are stopped but not traced (with ptrace(2)) because they received a SIGTTIN, SIGTTOU, SIGTSTP or SIGSTOP signal. See sigsys(2J) for a description of these signals.
RETURN VALUE
Returns −1 if there are no children not previously waited for, or 0 if the WNOHANG option is given and there are no stopped or exited children.
DIAGNOSTICS
Wait2 will fail and return immediately if one or more of the following is true:
[ECHILD] The calling process has no unwaited-for child processes.
[EFAULT] The w.w_status argument points to an address outside the process’s allocated address space.
RESTRICTIONS
This call is peculiar to this version of UNIX. The options and specifications of this system call and even the call itself are subject to change. It may be replaced by other facilities in future versions of the system.