sigaddset() — Add a signal to the signal mask
Standards
Standards / Extensions | C or C++ | Dependencies |
---|---|---|
POSIX.1 |
both |
Format
#define _POSIX_SOURCE
#include <signal.h>
int sigaddset(sigset_t *set, int signal);
General description
Adds a signal to the set of signals already recorded in set.
sigaddset() is part of a family of functions that manipulate signal sets. Signal sets are data objects that let a process keep track of groups of signals. For example, a process can create one signal set to record which signals it is blocking, and another signal set to record which signals are pending. In general, signal sets are used to manipulate groups of signals used by other functions (such as sigprocmask()) or to examine signal sets returned by other functions (such as sigpending()).
Applications should call either sigemptyset() or sigfillset() at least once for each object of type sigset_t prior to any other use of that object. If such an object is not initialized in this way, but is nonetheless supplied as an argument to any of pthread_sigmask(), sigaction(), sigaddset(), sigdelset(), sigismember(), sigpending(), sigprocmask(), sigsuspend(), sigtimedwait(), sigwait(), or sigwaitinfo(), the results are undefined.
Usage note
The use of the SIGTHSTOP and SIGTHCONT signal is not supported with this function.
Returned value
If the signal is successfully added to the signal set, sigaddset() returns 0.
If signal is not supported, sigaddset() returns -1 and sets errno to EINVAL.
Example
/* CELEBS15
This example adds a set of signals.
*/
#define _POSIX_SOURCE
#include <stdio.h>
#include <signal.h>
#include <unistd.h>
void catcher(int signum) {
puts("catcher() has gained control");
}
main() {
struct sigaction sact;
sigset_t sigset;
sigemptyset(&sact.sa_mask);
sact.sa_flags = 0;
sact.sa_handler = catcher;
sigaction(SIGUSR1, &sact, NULL);
puts("before first kill()");
kill(getpid(), SIGUSR1);
puts("before second kill()");
sigemptyset(&sigset);
sigaddset(&sigset, SIGUSR1);
sigprocmask(SIG_SETMASK, &sigset, NULL);
kill(getpid(), SIGUSR1);
puts("after second kill()");
}
before first kill()
catcher() has gained control
before second kill()
after second kill()
Related information
- signal.h
- sigaction() — Examine or change a signal action
- sigdelset() — Delete a signal from the signal mask
- sigemptyset() — Initialize a signal mask to exclude all signals
- sigfillset() — Initialize a signal mask to include all signals
- sighold() — Add a signal to a thread
- sigismember() — Test if a signal is in a signal mask
- signal() — Handle interrupts
- sigpause() — Unblock a signal and wait for a signal
- sigpending() — Examine pending signals
- sigprocmask() — Examine or change a thread
- sigset() — Change a signal action or a thread
- sigsuspend() — Change mask and suspend the thread