Syntax
#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.
Parameters
The possible values for how, which are defined in the <sys/signal.h> header file, are as follows:
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.
Return Value
Error Conditions
If sigprocmask() is not successful, errno usually indicates the following error. Under some conditions, errno could indicate an error other than that listed here.
A parameter passed to this function is not valid.
One of the following has occurred:
An attempt was made to call a signal function under one of the following conditions:
Usage Notes
Related Information
Example
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 );
}
Output:
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
| Signal APIs
| UNIX-Type APIs APIs by category |
| [Information Center Home Page | Feedback ] | [Legal | AS/400 Glossary] |