Home

WTERMSIG

WTERMSIG is a macro defined in the system header associated with process status information, used when inspecting the status value returned by wait or waitpid. It yields the termination signal number that caused a child process to terminate, and its result is meaningful only when WIFSIGNALED(status) is true.

In typical usage, a program calls wait or waitpid to obtain a status integer. The macro WIFSIGNALED(status)

WTERMSIG is used in conjunction with other macros that interpret the status value, such as WIFEXITED (normal

Portability and headers: WTERMSIG is defined by POSIX and is available on systems that conform to POSIX

Notes: WTERMSIG reflects the signal responsible for termination but does not by itself indicate whether a core

is
checked
to
determine
whether
the
child
was
terminated
by
a
signal.
If
so,
WTERMSIG(status)
provides
the
specific
signal
number
that
terminated
the
process,
which
can
then
be
reported
or
acted
upon
accordingly.
For
example,
after
waitpid,
if
(WIFSIGNALED(status))
{
int
sig
=
WTERMSIG(status);
/*
handle
termination
by
sig
*/
}.
termination)
and
WEXITSTATUS
(exit
code),
or
WIFSTOPPED
(process
stopped).
It
is
complementary
to
these
macros
and
helps
distinguish
the
cause
of
termination.
wait/status
conventions,
including
most
Unix-like
systems
such
as
Linux,
BSD
variants,
and
macOS.
The
relevant
macros
are
declared
in
headers
such
as
<sys/wait.h>
or
<wait.h>
depending
on
the
system.
dump
occurred;
use
WCOREDUMP(status)
to
check
for
a
core
dump
when
the
child
was
terminated
by
a
signal.
It
is
important
to
verify
WIFSIGNALED(status)
before
using
WTERMSIG(status).
See
also
WIFEXITED,
WEXITSTATUS,
WIFSTOPPED,
WCONTINUED,
and
wait/waitpid.