Home

sahandler

Sahandler refers to the signal handler designated by the sa_handler member of the POSIX sigaction structure. It is the function that the operating system will call in response to a specified signal when the action is installed as a handler rather than ignored or used with a default action. The handler function typically has the prototype void handler(int signum).

When a signal is delivered and sa_handler is in use, the kernel invokes the function pointed to

Usage typically involves defining a handler function, initializing a sigaction structure, assigning sa_handler, initializing sa_mask with

void sahandler(int sig) { /* handle signal */ }

struct sigaction act;

act.sa_handler = sahandler;

sigemptyset(&act.sa_mask);

act.sa_flags = 0;

sigaction(SIGINT, &act, NULL);

Sahandler is preferred in modern Unix-like systems over the older signal() interface because sigaction provides more

by
sa_handler
with
the
signal
number
as
its
sole
argument.
If
the
SA_SIGINFO
flag
is
set,
a
different
member,
sa_sigaction,
is
used,
and
the
handler
can
receive
additional
information
about
the
signal
via
a
three-argument
function.
The
sa_mask
member
specifies
a
set
of
signals
that
should
be
blocked
during
execution
of
the
handler,
and
sa_flags
controls
behavior
such
as
whether
system
calls
are
automatically
restarted
after
the
handler
returns
(SA_RESTART),
whether
the
handler
is
automatically
blocked
during
its
execution
(SA_NODEFER),
and
other
options.
sigemptyset(&act.sa_mask),
setting
appropriate
sa_flags,
and
calling
sigaction
for
the
desired
signal.
Example:
precise
control
over
masking,
information
delivery,
and
restart
behavior.
It
is
a
core
concept
in
interrupt-driven
and
asynchronous
programming
in
C
on
POSIX
platforms.