Signals: Fundamental Concepts 407
Multiple signals are represented using a data structure called a signal set, pro-
vided by the system data type sigset_t. SUSv3 specifies a range of functions for
manipulating signal sets, and we now describe these functions.
On Linux, as on most UNIX implementations, the sigset_t data type is a bit
mask. However, SUSv3 doesn’t require this. A signal set could conceivably be
represented using some other kind of structure. SUSv3 requires only that the
type of sigset_t be assignable. Thus, it must be implemented using either some
scalar type (e.g., an integer) or a C structure (perhaps containing an array of
integers).
The sigemptyset() function initializes a signal set to contain no members. The
sigfillset() function initializes a set to contain all signals (including all realtime signals).
One of sigemptyset() or sigaddset() must be used to initialize a signal set. This is
because C doesn’t initialize automatic variables, and the initialization of static vari-
ables to 0 can’t portably be relied upon as indicating an empty signal set, since signal
sets may be implemented using structures other than bit masks. (For the same
reason, it is incorrect to use memset(3) to zero the contents of a signal set in order to
mark it as empty.)
After initialization, individual signals can be added to a set using sigaddset() and
removed using sigdelset().
For both sigaddset() and sigdelset(), the sig argument is a signal number.
The sigismember() function is used to test for membership of a set.
The sigismember() function returns 1 (true) if sig is a member of set, and 0 (false)
otherwise.
#include <signal.h>
int sigemptyset(sigset_t *set);
int sigfillset(sigset_t *set);
Both return 0 on success, or –1 on error
#include <signal.h>
int sigaddset(sigset_t *set, int sig);
int sigdelset(sigset_t *set, int sig);
Both return 0 on success, or –1 on error
#include <signal.h>
int sigismember(const sigset_t *set, int sig);
Returns 1 if sig is a member of set, otherwise 0