int sigaction(int signum, const struct sigaction *act, struct sigaction *oldact);
int sigprocmask(int how, const sigset_t *set, sigset_t *oldset);
int sigpending(sigset_t *set);
int sigsuspend(const sigset_t *mask);
The sigaction structure is defined as
struct sigaction {
void (*sa_handler)();
sigset_t sa_mask;
int sa_flags;
void (*sa_restorer)(void);
}
sa_handler may be SIG_DFL for the default action, SIG_IGN to ignore this signal, or a pointer to a signal handling function.
sa_mask gives a mask of signals which should be blocked during execution of the signal handler.
sa_flags is the bitwise OR of zero or more of the following flags
- SA_NOCLDSTOP
- Do not generate SIGCHLD signals when child processes terminate.
- SA_ONESHOT
- Restore the signal action to the default state once the signal handler has been called. This is the default behavior.
- SA_RESTART
- The opposite to SA_ONESHOT, do not restore the signal action. This provides behavior compatible with BSD signal semantics.
- SA_NOMASK
- Do not prevent the signal from being received from within its own signal handler.
The sa_restorer element is obsolete and should not be used.
The sigprocmask call is used to change the list of currently blocked signals. The behavior of the call is dependent on the value of how, as follows.
- SIG_BLOCK
- The set of blocked signals is the union of the current set and the set argument.
- SIG_UNBLOCK
- The signals in set are removed from the current set of blocked signals. It is legal to attempt to unblock a signal which is not blocked.
- SIG_SETMASK
- The set of blocked signals is set to the argument set.
If oldset is non-null, the previous value of the signal mask is stored in oldset.
The sigpending call allows the examination of pending signals (ones which have been raised while blocked). The signal mask of pending signals is stored in set.
The sigsuspend call temporarily replaces the signal mask for the process with that given by mask and then suspends the process until a signal is received.
The POSIX spec only defines SA_NOCLDSTOP. Use of SA_ONESHOT and SA_RESTART is non-portable.
sigaction can be called with a null second argument to query the current signal handler. It can also be used to check whether a given signal is valid for the current machine by calling it with null second and third arguments.
See sigsetops(3) for details on manipulating signal sets.