wait2(2) CLIX wait2(2)
NAME
wait2, wait3 - Waits for a process to terminate
LIBRARY
wait2() - Standard C Library (libc.a)
wait3() - Berkeley Software Distribution Library (libbsd.a)
SYNOPSIS
#include <sys/types.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <sys/wait.h>
int wait2(
union wait *stat_loc ,
int options );
int wait3(
union wait *stat_loc ,
int options ,
struct rusage *rusage );
PARAMETERS
stat_loc Points to a structure that is filled in with the child process
termination status, as defined in the <sys/wait.h> header file.
options An integer flag to control the behavior of the function.
rusage Not used in this implementation.
DESCRIPTION
The wait2() function provides an alternate interface for programs that
must not block when collecting the status of child processes. The options
parameter indicates that the call should not block if no processes wish to
report status (WNOHANG), and/or that only children of the current process
that are stopped due to a SIGTTIN, SIGTTOU, SIGTSTP, or SIGSTOP signal
should have the status reported (WUNTRACED).
When the WNOHANG option is specified and no processes wish to report
status, wait2() returns a process ID of 0. The WNOHANG and WUNTRACED
options may be combined by a logical OR of the two values.
2/94 - Intergraph Corporation 1
wait2(2) CLIX wait2(2)
If stat_loc is nonzero, 16 bits of information called status are stored in
the low-order 16 bits of the location pointed to by stat_loc. The
stat_loc parameter can be used to differentiate between stopped and
terminated child processes. If the child process is terminated, stat_loc
identifies the cause of termination and passes useful information to the
parent. This is accomplished in the following manner:
⊕ If the child process is stopped, the high-order eight bits of the
status will contain the number of the signal that caused the process to
stop and the low-order eight bits will be set equal to 0177.
⊕ If the child process terminated due to an exit() call, the low-order
eight bits of status will be 0 and the high-order eight bits will
contain the low-order eight bits of the argument that the child process
passed to exit().
⊕ If the child process terminated due to a signal, the high-order eight
bits of status will be 0 and the low-order eight bits will contain the
number of the signal that caused the termination. In addition, if the
low-order seventh bit (bit 200) is set, a core(4) image file will have
been produced (see signal(2)).
If the 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)).
The wait3() function is implemented as wait2().
The rusage parameter is not used in this implementation.
EXAMPLE
To check for a child process:
int child_id,stat_loc;
extern int wait2();
child_id=wait2(&stat_loc,WNOHANG);
if(child_id==-1)
perror("wait2 error");
RETURN VALUES
The wait2() function returns -1 if there are no children not previously
waited for; 0 is returned if WNOHANG is specified and no stopped or
exited children exist.
If wait2() returns due to a stopped or terminated child process, the
process ID of the child is returned to the calling process. Otherwise, a
2 Intergraph Corporation - 2/94
wait2(2) CLIX wait2(2)
value of -1 is returned and errno is set to indicate the error.
ERRORS
The wait2() function fails and returns immediately if one or more of the
following is true:
[ECHILD]
The calling process has no existing unwaited-for child processes.
[EFAULT]
The stat_loc parameter points to an illegal address.
RELATED INFORMATION
Functions: sigcld(2), signal(2), exit(2), wait(2), fork(2), pause(2),
ptrace(2)
2/94 - Intergraph Corporation 3