waitpid(2)

DESCRIPTION

Selects a child by positive PID, any child with −1, the caller's process group with zero, or a specified process group with a negative PID. It blocks until a selected child exits, stops when WUNTRACED is set, or reports a pending continuation when WCONTINUED is set. WNOHANG returns zero when no selected event is ready.

SYNOPSIS

long waitpid(int pid, int *status, uint32_t options);

RETURN VALUE

  • Returns the selected child PID, zero only for WNOHANG with no ready event, or a negative errno. On exit, status uses the traditional layout: signal termination is signal & 0177, normal exit is (exit_status & 0377) << 8, stopped status is (stop_signal << 8) | 0177, and continuation is 0xffff.

ERRORS

  • -EFAULT
    • Status is non‑null but not writable userspace memory.
  • -ECHILD
    • The caller has no matching child.
  • -EINVAL
    • Pid selects an invalid process or group identifier, or options contains an unknown bit.
  • -ESRCH
    • There is no current process or thread.

NOTES

A successful exit event is reaped. Stop and continuation notifications are consumed but do not reap the child.