Specifies the action to take upon delivery of a signal.
#include <signal.h> int sigaction (int sig, const struct sigaction *action, struct sigaction *o_action);
If sig is SIGCHLD and the SA_NOCLDSTOP flag is not set in sa_flags, then a SIGCHLD signal is generated for the calling process whenever any of its child processes stop. If sig is SIGCHLD and the SA_NOCLDSTOP flag is set in sa_flags, then SIGCHLD signal is not generated in this way.
The sigaction structure consists of the following members:
void (*sa_handler)(int); sigset_t sa_mask; int sa_flags;
The sigaction structure members are defined as follows:
sa_handler | This member can contain the
following values:
|
sa_mask | This member can request that individual signals, in addition to those in the process signal mask, are blocked from delivery while the signal handler function specified by the sa_handler member is executing. |
sa_flags | This member can set the flags to enable further control over the actions taken when a signal is delivered. |
The sa_flags member of the sigaction structure has the following values:
SA_ONSTACK | Setting this bit causes the system to run the signal catching function on the signal stack specified by the sigstack function. If this bit is not set, the function runs on the stack of the process where the signal is delivered. |
SA_RESETHAND | Setting this bit resets the signal to SIG_DFL. Be aware that you cannot automatically reset SIGILL and SIGTRAP. |
SA_NODEFER | Setting this bit does not automatically block the signal as it is caught. |
SA_NOCLDSTOP | If this bit is set and the sig argument is equal to SIGCHLD and a child process of the calling process stops, then a SIGCHLD signal is sent to the calling process only if SA_NOCLDSTOP is not set for SIGCHLD. |
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 or sigsuspend 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 unless SA_NODEFER or SA_ RESETHAND is set, 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), until the SA_RESETHAND flag causes resetting of the handler, or until one of the exec functions is called.
If the previous action for a specified signal had been established by signal, the values of the fields returned in the structure pointed to by the o_action argument of sigaction are unspecified, and in particular o_action->sa_handler is not necessarily the same value passed to signal. However, if a pointer to the same structure or a copy thereof is passed to a subsequent call to sigaction by means of the action argument of sigaction), the signal is handled as if the original call to signal were repeated.
If sigaction fails, no new signal handler is installed.
It is unspecified whether an attempt to set the action for a signal that cannot be caught or ignored to SIG_DFL is ignored or causes an error to be returned with errno set to EINVAL.
See Section 4.2 for more information on signal handling.
See also sigstack, sigvec, signal, wait, read, and write, in this section.
0 | Indicates success. |
-1 | Indicates an error; A new signal handler
is not installed. errno is set to one of the following values:
|