sigpending()--Examine Pending Signals
Syntax
#include <signal.h> int sigpending( sigset_t *set );
Service Program Name: QPOSSRV1
Default Public Authority: *USE
Threadsafe: Yes
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 about examining the signal set pointed to by set, see sigismember()--Test for Signal in Signal Set.
Authorities and Locks
None.
Parameters
- *set
- (Output) A pointer to the space where the signal set information is stored.
Return Value
| 0 | sigpending() was successful. |
| -1 | sigpending() was not successful. The errno variable is set to indicate the error. |
Error Conditions
If sigpending() is not successful, errno usually indicates the following error. Under some conditions, errno could indicate an error other than that listed here.
- [ENOTSIGINIT]
-
Process not enabled for signals.
An attempt was made to call a signal function under one of the following conditions:
- The signal function is being called for a process that is not enabled for
asynchronous signals.
- The signal function is being called when the system signal controls have not been initialized.
- The signal function is being called for a process that is not enabled for
asynchronous signals.
Related Information
- The <signal.h> file (see Header
Files for UNIX®-Type Functions)
- sigaddset()--Add Signal to Signal Set
- sigdelset()--Delete Signal from Signal Set
- sigemptyset()--Initialize and Empty Signal
Set
- sigfillset()--Initialize and Fill Signal Set
- sigismember()--Test for Signal in Signal Set
- sigprocmask()--Examine and Change Blocked Signals
Example
The following example returns blocked and pending signals.
Note: By using the code examples, you agree to the terms of the Code license and disclaimer information.
#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 );
}
Output:
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
API introduced: V3R6