waitid Subroutine

Purpose

Waits for a child process to change state.

Library

Standard C Library (libc.a)

Syntax

#include <sys/wait.h>;

int waitid (idtype, id, infop,  options)
idtype_t idtype;
id_t id;
siginfo_t *infop;
int options; 

Description

The waitid subroutine suspends the calling thread until one child of the process containing the calling thread changes state. It records the current state of a child in the structure pointed to by the infop parameter. If a child process changed state prior to the call to the waitid subroutine, the waitid subroutine returns immediately. If more than one thread is suspended in the wait or waitpid subroutines waiting for termination of the same process, exactly one thread will return the process status at the time of the target process termination.

Parameters

Item Description
idtype Specifies the child process.
id Specifies the child process.
infop Specifies the location of a siginfo_t structure to be filled in with resource utilization information.
options Specifies which state changes the waitid subroutine will wait for. It is formed by OR'ing together one or more of the following flags:
WEXITED
Wait for processes that have exited.
WSTOPPED
Status will be returned for any child that has stopped upon receipt of a signal.
WCONTINUED
Status will be returned for any child that was stopped and has been continued.
WNOHANG
Return immediately if there are no children to wait for.
WNOWAIT
Keep the process whose status is returned in the infop parameter in a waitable state. This will not affect the state of the process. The process can be waited for again after this call completes.

Return Values

If WNOHANG was specified and there are no children to wait for, 0 is returned. If the waitid subroutine returns due to the change of state of one of its children, 0 is returned. Otherwise, -1 is returned and errno is set to indicate the error.

Error Codes

The waitid subroutine will fail if:
Item Description
ECHILD The calling process has no existing unwaited-for child processes.
EINTR The waitid subroutine was interrupted by a signal.
EINVAL An invalid value was specified for the options, or idtype parameters and the id parameter specifies an invalid set of processes.