Home

sigaction

Sigaction is a POSIX API used to define and control how a process handles signals. It provides a more consistent and portable mechanism than the older signal() interface, allowing precise specification of the handler and the context in which it runs.

The core data type is struct sigaction, which includes:

- sa_handler, a pointer to a function taking an int (the signal number); or sa_sigaction, a pointer

- sa_mask, a signal set that specifies which signals should be blocked during execution of the signal

- sa_flags, a set of options that modify handler behavior (see below).

- sa_restorer, a historical field present on some systems (often unused and considered obsolete).

To install a handler, a program fills a struct sigaction and calls sigaction(signum, &act, oldact). If oldact

Common flags include:

- SA_RESTART, to automatically restart certain interrupted system calls.

- SA_NODEFER, to avoid blocking the signal while its handler runs.

- SA_RESETHAND, to reset the handler to default behavior after the signal is handled.

- SA_SIGINFO, to supply additional information to the handler via the siginfo_t structure.

- SA_ONSTACK, to use an alternate signal stack.

Notes: sigaction is the standard, portable interface for signal handling across POSIX systems (Linux, BSD, macOS,

to
a
function
taking
(int,
siginfo_t
*,
void
*)
when
extended
information
is
needed.
handler.
is
non-NULL,
the
previous
action
for
signum
is
returned.
If
SA_SIGINFO
is
set
in
sa_flags,
the
handler
pointed
to
by
sa_sigaction
is
used;
otherwise
sa_handler
is
used.
etc.).
Differences
may
exist
in
edge
cases
and
real-time
signals.
It
supersedes
signal()
by
offering
precise
control
over
handler
type,
masking,
and
behavior.