#include <signal.h> int sigpending( sigset_t *set );
The sigpending() function returns signals that are blocked from delivery and pending for either the calling thread or the process. This information is represented as a signal set stored in set. For more information on examining the signal set pointed to by set, see sigismember()--Test for Signal in Signal Set.
None.
0 | sigpending() was successful. |
-1 | sigpending() was not successful. The errno variable is set to indicate the error. |
If sigpending() is not successful, errno usually indicates the following error. Under some conditions, errno could indicate an error other than that listed here.
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 returns blocked and pending signals:
#include <signal.h> #include <unistd.h> #include <stdio.h> void catcher( int sig ) { puts( "inside catcher() function\n" ); } void check_pending( int sig, char *signame ) { sigset_t sigset; if( sigpending( &sigset ) != 0 ) perror( "sigpending() error\n" ); else if( sigismember( &sigset, sig ) ) printf( "a %s signal is pending\n", signame ); else printf( "no %s signals are pending\n", signame ); } int main( int argc, char *argv[] ) { struct sigaction sigact; sigset_t sigset; sigemptyset( &sigact.sa_mask ); sigact.sa_flags = 0; sigact.sa_handler = catcher; if( sigaction( SIGUSR1, &sigact, NULL ) != 0 ) perror( "sigaction() error\n" ); else { sigemptyset( &sigset ); sigaddset( &sigset, SIGUSR1 ); if ( sigprocmask( SIG_SETMASK, &sigset, NULL ) != 0) perror( "sigprocmask() error\n" ); else { printf( "SIGUSR1 signals are now blocked\n" ); kill( getpid(), SIGUSR1 ); printf( "after kill()\n" ); check_pending( SIGUSR1, "SIGUSR1" ); sigemptyset( &sigset ); sigprocmask( SIG_SETMASK, &sigset, NULL ); printf( "SIGUSR1 signals are no longer blocked\n" ); check_pending( SIGUSR1, "SIGUSR1" ); } } return( 0 ); }
SIGUSR1 signals are now blocked after kill() a SIGUSR1 signal is pending inside catcher() function SIGUSR1 signals are no longer blocked no SIGUSR1 signals are pending
Top | UNIX-Type APIs | APIs by category |