Home

SIGCHLDs

SIGCHLD is a signal in POSIX-compliant Unix-like systems sent to a process when one of its child processes changes state. A child may terminate, be terminated by a signal, stop due to a job-control signal, or continue after being stopped. The signal serves as notification that the parent may need to examine or reap the child’s exit status.

Delivery and handling: The signal is delivered to the parent process of the child. The default action

Handling patterns: A typical approach is to install a handler for SIGCHLD and reap children with waitpid

Importance for process management: Reaping children prevents zombie processes and frees system resources. Because signal delivery

Notes and terminology: SIGCHLD is sometimes referred to in historical code as CLD. The plural notion SIGCHLDs

is
to
ignore
SIGCHLD,
but
the
signal
is
generated
regardless.
When
multiple
children
change
state,
the
signal
may
be
delivered
multiple
times.
Some
systems
can
suppress
delivery
of
SIGCHLD
when
children
stop
by
using
flags
such
as
SA_NOCLDSTOP.
in
a
loop,
using
WNOHANG
to
avoid
blocking.
Alternatively,
parents
may
poll
for
status
changes.
The
status
returned
by
wait
or
waitpid
can
be
interpreted
with
macros
such
as
WIFEXITED,
WEXITSTATUS,
WIFSIGNALED,
WTERMSIG,
WIFSTOPPED,
WSTOPSIG,
and
on
some
systems
WIFCONTINUED.
is
asynchronous,
robust
programs
often
reap
all
available
children
in
the
handler.
Programs
should
use
sigaction
rather
than
the
older
signal
API
for
reliable
behavior
and
consider
race-condition
mitigations
when
setting
up
handlers.
refers
to
occurrences
of
the
signal
raised
for
different
children
rather
than
a
separate
signal
type.
This
signal
is
central
to
how
shells,
daemons,
and
other
parent
processes
manage
child
lifecycles.