Wednesday, October 19, 2011

sigprocmask linux

sigprocmask Function

the signal mask of a process is the set of signals currently blocked from delivery to that process. A process can examine its signal mask, change its signal mask, or perform both operations in one step by calling the following function.

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.

#include <signal.h>

int sigprocmask(int how, const sigset_t *restrict set,
sigset_t *restrict oset);

Returns: 0 if OK, 1 on error

  1. First, if oset is a non-null pointer, the current signal mask for the process is returned through oset. 
  2. Second, if set is a non-null pointer, the how argument indicates how the current signal mask is modified. Figure below describes the possible values for how. SIG_BLOCK is an inclusive-OR operation, whereas SIG_SETMASK is an assignment. Note that SIGKILL and SIGSTOP can't be blocked.
Figure : Ways to change current signal mask using sigprocmask

How
Description
SIG_BLOCK
The new signal mask for the process is the union of its current signal
mask and the signal set pointed to by set. That is, set contains the
additional signals that we want to block.
SIG_UNBLOCK
The new signal mask for the process is the intersection of its current
signal mask and the complement of the signal set pointed to by set.
That is, set contains the signals that we want to unblock.
SIG_SETMASK
The new signal mask for the process is replaced by the value of the
signal set pointed to by set.

If set is a null pointer, the signal mask of the process is not changed, and how is ignored. After calling sigprocmask, if any unblocked signals are pending, at least one of these signals is delivered to the process before sigprocmask returns.

The sigprocmask function is defined only for single-threaded processes. A separate function is provided to manipulate a thread's signal mask in a multithreaded process.

No comments:

Post a Comment