Next: Process Signal Mask, Previous: Why Block, Up: Blocking Signals
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.
The
sigset_tdata 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_tobjects—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.)
This function initializes the signal set set to exclude all of the defined signals. It always returns
0.
This function initializes the signal set set to include all of the defined signals. Again, the return value is
0.
This function adds the signal signum to the signal set set. All
sigaddsetdoes is modify set; it does not block or unblock any signals.The return value is
0on success and-1on failure. The followingerrnoerror condition is defined for this function:
EINVAL- The signum argument doesn't specify a valid signal.
This function removes the signal signum from the signal set set. All
sigdelsetdoes is modify set; it does not block or unblock any signals. The return value and error conditions are the same as forsigaddset.
Finally, there is a function to test what signals are in a signal set:
The
sigismemberfunction tests whether the signal signum is a member of the signal set set. It returns1if the signal is in the set,0if not, and-1if there is an error.The following
errnoerror condition is defined for this function:
EINVAL- The signum argument doesn't specify a valid signal.