[Previous]
[Contents]
[Next]

wait()

suspend execution of the calling process

Synopsis:

#include <sys/types.h>
#include <sys/wait.h>
pid_t wait( int *stat_loc );

Description:

The wait() function suspends execution of the calling process 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 wait(), the return is immediate.

If the stat_loc variable is non-NULL, the terminating status of the child process is placed here. The macros listed below extract information from stat_loc. The stat_val argument to these macros is the integer value pointed to by stat_loc. At least the following macros are defined in <sys/wait.h>:

WIFEXITED( stat_val )
Evaluates to a nonzero value if the status returned was from a normally terminated child process.
WEXITSTATUS( stat_val )
If the value of WIFEXITED( stat_val ) is nonzero, this macro evaluates to the low-order 8 bits of the termination status of the child process.
WIFSIGNALED( stat_val )
Evaluates to nonzero value if the child process terminated from reception of a signal that wasn't caught.
WTERMSIG( stat_val )
If the value of WIFSIGNAL( stat_val ) is nonzero, this macro evaluates to the number of the signal that terminated the child process.
WIFSTOPPED( stat_val )
Evaluates to a nonzero value if the status returned is for a child process that is stopped.
WSTOPSIG( stat_val )
If the value of WIFSTOPPED( stat_val ) is nonzero, this macro evaluates to the number of the signal that caused the child process to stop.

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

Returns:

The process ID of the terminating child process, if successful. Upon delivery of a signal, wait() returns -1 and errno is set to EINTR.

Errors:

ECHILD
The calling process has no existing unwaited-for child processes.
EINTR
The function was interrupted by a signal. The value of the location pointed to by stat_loc is undefined.

Examples:

See fork().

Classification:

POSIX 1003.1

Safety:
Interrupt handler No
Signal handler Yes
Thread Yes

See also:

errno, signal(), waitpid()


[Previous]
[Contents]
[Next]