SIGACTION(2) SysV SIGACTION(2)
NAME
sigaction - examine and changed signal action
SYNOPSIS
#include <signal.h>
int sigaction (signal, action, o_action)
int signal;
const struct sigaction *action;
struct sigaction *o_action;
DESCRIPTION
The sigaction function allows the calling process to examine and/or
change the action to be taken when a specific signal is delivered to the
process issuing this function. signal specifies the signal; acceptable
values are defined in <signal.h>.
The sigaction structure, defined in <signal.h>, has the following
members:
void (*sa_handler)(int); Signal handler action
sigset_t sa_mask; Signal mask
int sa_flags; Modification to specified signal
If action is not null, it points to a sigaction structure specifying the
action to be associated with the specified signal. If o_action is not
null, it points to a sigaction structure into which the action previously
associated with the signal is stored. If action is null, signal handling
is unchanged; thus, the call can be used to inquire about the current
handling of a given signal.
The sa_handler field identifies the action associated with a specified
signal.
If the sa_handler field specifies a signal-catching function, the sa_mask
field identifies a set of signals that will be added to the process'
signal mask before the signal-catching function is invoked. Note that the
SIGKILL and SIGSTOP signals are not added to the signal mask using this
mechanism.
The sa_flags field can be used to modify the behavior of the specified
signal. The following flag bit, defined in <signal.h> can be set in
sa_flags:
SA_NOCLDSTOP Do not generate SIGCHLD when children stop.
If signal is SIGCHLD and the SA_NOCLDSTOP flag is not set in sa_flags,
then a SIGCHLD signal will be generaed for the calling process whenever
any of its child processes stop. If signal is SIGCHLD and the
SA_NOCLDSTOP flag is set in sa_flags, then a SIGCHLD signal will not be
generaed.
When a signal is caught by a signal-catching function installed by
sigaction, a new signal mask is calculated and installed for the duration
of the signal-catching function (or until a call to either sigprocmask(2)
or sigsuspend(2) is made). This mask is formed by taking the union of the
current signal mask and the value of the sa_mask for the signal being
delivered, and then including the signal being delivered. If and when the
user's signal handler returns normally, the original signal mask is
restored.
Once an action is installed for a specific signal, it remains installed
until another action is explicitly requested (by another call to
sigaction), or until one of the exec functions is called.
If sigaction fails, no new signal handler is installed.
NOTES
The signal(2) function provides a subset of features available with the
sigaction function.
The func argument of signal(2) can have the same values that are
described for the sa_handler field in the sigaction structure of
sigaction function. However, no signal handler mask or flags can be
specified. Refer to signal(2) for details.
In a multi-threaded environment, sigaction should only be used for
synchronous signals.
DIAGNOSTICS
Upon successful completion of sigaction, a value of 0 (zero) is returned.
Otherwise, a value of -1 is returned and errno is set to indicate the
error, and no new signal-catching functions are installed.
ERRORS
sigaction fails if:
[EINVAL] The signal argument is not a valid signal number.
[EINVAL] An attempt was made to ignore or supply a handler for the
SIGKILL, SIGSTOP, and SIGCONT signals.
SEE ALSO
exit(2), kill(2), raise(2) sigsetops(3) signal(2) sigprocmask(2),
sigsuspend(2), <signal.h>