wait4()

Wait for one or more child process to change its state

Synopsis:

#include <sys/wait.h>
#include <sys/resource.h>

pid_t wait4( pid_t pid, 
             int * stat_loc, 
             int options, 
             struct rusage * resource_usage );

Arguments:

pid
The set of child processes that you want to get status information for:
stat_loc
NULL, or a pointer a location where the function can store the terminating status of the child process. For information about macros that extract information from this status, see Status macros in the documentation for wait().
options
A combination of zero or more of the following flags:
resource_usage
NULL, or a pointer to a rusage structure where the function can store information about resource usage. For information about this structure, see getrusage().

Library:

libc

Use the -l c option to qcc to link against this library. This library is usually included automatically.

Description:

The wait4() function suspends execution of the calling thread until status information from one of its terminated child processes is available, or until the delivery of a signal whose action is either to terminate the process or execute a signal handler. If status information is available prior to the call to wait4(), the return is immediate.


Note: If the parent process sets the action for SIGCHLD to SIG_IGN, its children won't enter the zombie state, and it won't be able to use the wait*() functions to wait on their deaths.

The wait4() function behaves the same as the wait() function when passed a pid argument of -1, and the options argument has a value of zero.

Only one of the WIFEXITED(stat_val) and WIFSIGNALED(stat_val) macros can evaluate to a nonzero value.

The following call:

wait3( stat_loc, options, resource_usage );

is equivalent to the call:

waitpid( (pid_t)-1, stat_loc, options );

except that on successful completion, if the resource_usage argument to wait3() isn't a NULL pointer, the rusage structure that the third argument points to is filled in for the child process identified by the return value.

It's also equivalent to:

wait4( (pid_t)-1, stat_loc, options, resource_usage );

The waitpid() function is POSIX: wait3() and wait4() are BSD extensions.

Returns:

If successful, wait4() returns the process ID of the terminating child process. If wait4() was invoked with WNOHANG set in options, it has at least one child process specified by pid for which status is not available, and status is not available for any process specified by pid, a value of zero is returned. On delivery of a signal waitpid() returns -1, and errno is set to EINTR.

Errors:

ECHILD
The calling process has no existing unwaited-for child processes that meet the criteria set by pid.
EINTR
The function was interrupted by a signal. The value of the location pointed to by stat_loc is undefined.
EINVAL
The value of the options argument isn't valid.

Classification:

Unix

Safety:
Cancellation point Yes
Interrupt handler No
Signal handler Yes
Thread Yes

See also:

exit(), fork(), pause(), wait(), wait3(), waitid(), waitpid()

Detecting process termination in the “Processes” chapter of the QNX Neutrino Programmer's Guide