gtpc2m6uC/C++ Language Support User's Guide

sigprocmask-Examine and Change Blocked Signals

This function allows the calling process to examine (query) or change its signal mask. Each process has a signal mask that specifies a set of signals that cannot be raised. These are called blocked signals. A blocked signal can be sent to a process, but it remains pending until it is unblocked and subsequently raised.

Format

#include <signal.h>
int sigprocmask(  int            change,
                const sigset_t  *set,
                      sigset_t  *oset);

change
If the signal set pointed to by the set parameter is not NULL, the change parameter indicates the way in which the signal mask (the set of signals currently blocked) is changed. This parameter must be specified as one of the following:

SIG_BLOCK
All signals in the signal set pointed to by the set parameter are to be added to the current signal set for the process.

SIG_SETMASK
The signal set pointed to by the set parameter replaces the current signal mask for the process.

SIG_UNBLOCK
All signals in the signal set pointed to by the set parameter are to be removed from the current signal set for the process.

If the signal set pointed to by the set parameter is NULL, the change parameter is ignored.

set
One of the following:

oset
One of the following:

Note:
The description of the set parameter describes the results of sigprocmask function processing based on the value specified for the oset parameter.

Normal Return

If successful, the sigprocmask function returns a value of zero.

Error Return

If unsuccessful, the signal mask for the process is not changed and the sigprocmask function returns a value of -1 and sets errno to the following:

EINVAL
The value of the change parameter is not valid; it must be one of the values listed for the change parameter.

Programming Considerations

Examples

The following example shows how to block all signals.

#include <signal.h>

·
·
·
{ struct sigaction act, oact; sigset_t new_mask; sigset_t old_mask; /* initialize the new signal mask */ sigfillset(&new_mask); /* block all signals */ sigprocmask(SIG_SETMASK, &new_mask, &old_mask); /* call function */ somefunc(); /* restore signal mask */ sigprocmask(SIG_SETMASK, &old_mask, NULL);
·
·
·
}

Related Information