The GNU C Library - Signal Sets

Node: Signal Sets Next: Process Signal Mask Prev: Why Block Up: Blocking Signals

Signal Sets

All of the signal blocking functions use a data structure called a signal set to specify what signals are affected. Thus, every activity involves two stages: creating the signal set, and then passing it as an argument to a library function.

These facilities are declared in the header file `signal.h'.

Data Type sigset_t
The sigset_t data type is used to represent a signal set. Internally, it may be implemented as either an integer or structure type.

For portability, use only the functions described in this section to initialize, change, and retrieve information from sigset_t objects---don't try to manipulate them directly.

There are two ways to initialize a signal set. You can initially specify it to be empty with sigemptyset and then add specified signals individually. Or you can specify it to be full with sigfillset and then delete specified signals individually.

You must always initialize the signal set with one of these two functions before using it in any other way. Don't try to set all the signals explicitly because the sigset_t object might include some other information (like a version field) that needs to be initialized as well. (In addition, it's not wise to put into your program an assumption that the system has no signals aside from the ones you know about.)

Function int sigemptyset (sigset_t *set)
This function initializes the signal set set to exclude all of the defined signals. It always returns 0 .

Function int sigfillset (sigset_t *set)
This function initializes the signal set set to include all of the defined signals. Again, the return value is 0 .

Function int sigaddset (sigset_t *set, int signum)
This function adds the signal signum to the signal set set. All sigaddset does is modify set; it does not block or unblock any signals.

The return value is 0 on success and -1 on failure. The following errno error condition is defined for this function:

EINVAL
The signum argument doesn't specify a valid signal.

Function int sigdelset (sigset_t *set, int signum)
This function removes the signal signum from the signal set set. All sigdelset does is modify set; it does not block or unblock any signals. The return value and error conditions are the same as for sigaddset .

Finally, there is a function to test what signals are in a signal set:

Function int sigismember (const sigset_t *set, int signum)
The sigismember function tests whether the signal signum is a member of the signal set set. It returns 1 if the signal is in the set, 0 if not, and -1 if there is an error.

The following errno error condition is defined for this function:

EINVAL
The signum argument doesn't specify a valid signal.


Next: Process Signal Mask Up: Blocking Signals