[Previous]
[Contents]
[Next]

sigprocmask()

examine or change the signal mask for a process

Synopsis:

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

Description:

The sigprocmask() function is used to examine or change (or both) the signal mask for the calling process. If the value of set isn't NULL, it points to a set of signals to be used to change the currently blocked set. The value of how indicates the manner in which the set is changed:

SIG_BLOCK
add the signals pointed to by set to the process mask
SIG_UNBLOCK
remove the signals pointed to by set from the process mask
SIG_SETMASK
set the process mask to be the signals pointed to by set

The set argument isn't changed. The resulting set is maintained in the process table of the calling process. If a signal occurs on a signal that's masked, it becomes pending, but won't effect the execution of the process. You may examine pending signals using the sigpending function. When a pending signal is unmasked, it will be acted upon immediately, before this function returns.

If the argument oset isn't NULL, the previous mask is saved there. If the argument set is NULL, the argument how is ignored.

It isn't possible to block the SIGKILL or SIGHOLD signals, unless the _PPF_IMMORTAL flag is set using the function qnx_pflags().

When a signal handler is invoked, the signal responsible is automatically masked before its handler is called. If the handler returns normally, the operating system will restore the signal mask present just before the handler was called as an atomic operation. Changes made using sigprocmask() in the handler will be undone.

The sigaction() function allows you to specify any mask that is applied before a handler is invoked. This can simplify multiple signal handler design.

Returns:

0
Success
-1
An error occurred. errno is set to indicate the error.

Errors:

EINVAL
The signal signo isn't valid.

Examples:

#include <stdio.h>
#include <signal.h>
#include <unistd.h>

void main()
  {
    sigset_t set, oset, pset;

    sigemptyset( &set );
    sigaddset( &set, SIGINT );
    sigprocmask( SIG_BLOCK, &set, &oset );
    printf( "Old set was %8.8ld.\n", oset );

    sigpending( &pset );
    printf( "Pending set is %8.8ld.\n", pset );

    kill( getpid(), SIGINT );

    sigpending( &pset );
    printf( "Pending set is %8.8ld.\n", pset );

    sigprocmask( SIG_UNBLOCK, &set, &oset );

    /* The program terminates with a SIGINT */
  }

Classification:

POSIX 1003.1

Safety:
Interrupt handler No
Signal handler Yes, but modifies errno
Thread Yes

See also:

errno, kill(), raise(), sigaction(), sigaddset(), sigdelset(), sigemptyset(), sigfillset(), sigismember(), signal(), sigpending()


[Previous]
[Contents]
[Next]