Home

waitwaitpid

Waitwaitpid is not a single system call but a reference to the family of POSIX APIs used to reap state changes of child processes, typically involving the wait and waitpid functions. These calls let a parent process synchronize with its children and collect exit status information, helping to prevent zombie processes.

The wait function provides a simple, blocking mechanism. int wait(int *status) waits for any child process to

The waitpid function offers finer control. int waitpid(pid_t pid, int *status, int options) selects which child

Status information is interpreted with macros such as WIFEXITED, WEXITSTATUS, WIFSIGNALED, WTERMSIG, WIFSTOPPED, WSTOPSIG, and WIFCONTINUED,

Usage scenarios include implementing shells, daemons, and resource managers that need reliable child lifecycle handling. While

terminate,
blocking
until
one
does.
It
returns
the
PID
of
the
terminated
child,
or
-1
on
error.
If
status
is
non-null,
it
is
filled
with
information
about
how
the
child
terminated,
such
as
normal
exit,
being
killed
by
a
signal,
or
a
stop/continue
event.
to
wait
for
using
pid.
A
positive
pid
waits
for
that
specific
child;
pid
==
0
waits
for
any
child
in
the
caller’s
process
group;
pid
<
-1
waits
for
any
child
in
the
process
group
|pid|;
pid
==
-1
waits
for
any
child.
The
options
parameter
can
include
WNOHANG
(nonblocking),
WUNTRACED
(report
stopped
children),
WCONTINUED
(report
continued
children),
and,
in
some
systems,
WNOWAIT
(don’t
reap
the
child).
The
function
returns
the
PID
of
the
child
that
changed
state,
0
if
WNOHANG
was
used
and
no
state
change
occurred,
or
-1
on
error.
which
indicate
how
the
child
ended
or
changed
state
and
any
associated
codes
or
signals.
waitpid
is
more
flexible,
wait
remains
a
simple
option
for
waiting
on
any
child
when
fine-grained
control
is
unnecessary.