#include <signal.h> int sigprocmask( int how, const sigset_t *set, sigset_t *oset );
The sigprocmask() function examines, or changes, or both examines and changes the signal mask of the calling thread.
The signals SIGKILL or SIGStop cannot be blocked. Any attempt to use sigprocmask() to block these signals is simply ignored, and no error is returned.
SIGFPE, SIGILL, and SIGSEGV signals that are not artificially generated by kill() or raise() (that is, were generated by the system as a result of a hardware or software exception) are not blocked.
If there are any pending unblocked signals after sigprocmask() has changed the signal mask, at least one of those signals is delivered to the thread before sigprocmask() returns.
If sigprocmask() fails, the process's signal mask is not changed.
None.
The possible values for how, which are defined in the <sys/signal.h> header file, are as follows:
SIG_BLOCK | Indicates that the set of signals given by set should be blocked, in addition to the set currently being blocked. |
SIG_UNBLOCK | Indicates that the set of signals given by set should not be blocked. These signals are removed from the current set of signals being blocked. |
SIG_SETMASK | Indicates that the set of signals given by set should replace the old set of signals being blocked. |
The set parameter points to a signal set giving the new signals that should be blocked or unblocked (depending on the value of how), or it points to the new signal mask if the value of how was SIG_SETMASK. Signal sets are described in sigemptyset()--Initialize and Empty Signal Set. If set is a NULL pointer, the set of blocked signals is not changed. If set is NULL, the value of howis ignored.
The signal set manipulation functions (sigemptyset(), sigfillset(), sigaddset(), and sigdelset()) must be used to establish the new signal set pointed to by set.
sigprocmask() determines the current signal set and returns this information in *oset. If set is NULL, oset returns the current set of signals being blocked. When set is not NULL, the set of signals pointed to by oset is the previous set.
0 | sigprocmask() was successful. |
-1 | sigprocmask() was not successful. The errno variable is set to indicate the error. |
If sigprocmask() is not successful, errno usually indicates the following error. Under some conditions, errno could indicate an error other than that listed here.
The value specified for the argument is not correct.
A function was passed incorrect argument values, or an operation was attempted on an object and the operation specified is not supported for that type of object.
An argument value is not valid, out of range, or NULL.
One of the following has occurred:
Process not enabled for signals.
An attempt was made to call a signal function under one of the following conditions:
See Code disclaimer information for information pertaining to code examples.
The following example changes the signal mask:
#include <signal.h> #include <unistd.h> #include <stdio.h> #include <time.h> void catcher( int sig ) { printf( "inside catcher() function\n" ); } int main( int argc, char *argv[] ) { time_t start, finish; struct sigaction sact; sigset_t new_set, old_set; double diff; sigemptyset( &sact.sa_mask ); sact.sa_flags = 0; sact.sa_handler = catcher; sigaction( SIGALRM, &sact, NULL ); sigemptyset( &new_set ); sigaddset( &new_set, SIGALRM ); sigprocmask( SIG_BLOCK, &new_set, &old_set); time( &start ); printf( "SIGALRM signals blocked at %s\n", ctime(&start) ); alarm( 1 ); /* SIGALRM will be sent in 1 second */ do { time( &finish ); diff = difftime( finish, start ); } while (diff < 10); sigprocmask( SIG_SETMASK, &old_set, NULL ); printf( "SIGALRM signals unblocked at %s\n", ctime(&finish) ); return( 0 ); }
SIGALRM signals blocked at Sun Jan 22 16:53:40 1995 inside catcher() function SIGALRM signals unblocked at Sun Jan 22 16:53:50 1995
Top | UNIX-Type APIs | APIs by category |