gtpc2m6u | C/C++ Language Support User's Guide |
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:
- A pointer to a signal set that is used to modify the signal mask according
to the change parameter. The signal set is of the
sigset_t type.
- If the oset parameter is a pointer to a signal set, the value
of the signal mask before the sigprocmask function call is stored
in the signal set referenced by the oset parameter, and the signal
mask is changed as specified by the change and set
parameters.
- If the oset parameter is NULL, the signal mask is changed as
specified by the change and set parameters.
- A value of NULL.
- If the oset parameter is a pointer, the value of the signal
mask stored in the signal set referenced by the oset parameter and
the signal mask is not changed.
- If the oset parameter is NULL, the signal mask is not examined
or changed.
- oset
- One of the following:
- A pointer to a signal set where the signal mask for the process is stored
when the sigprocmask function is called. The signal set is
of the sigset_t type.
- A value of NULL.
- 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