sigpending()--Examine Pending Signals

http://publib.boulder.ibm.com/infocenter/iseries/v5r3/index.jsp?topic=%2Fapis%2Fsigpend.htm

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 blockedfrom delivery and pending for either the calling thread or the process. Thisinformation is represented as a signal set stored in set. For moreinformation on examining the signal set pointed to by set, see sigismember()--Test for Signal in Signal Set.


Parameters

*set
(Output) A pointer to the space where the signal set information isstored.

Return Value

0 sigpending() wassuccessful.
-1 sigpending() was not successful.The errno variable is set to indicate the error.


Error Conditions

If sigpending() is not successful, errno usuallyindicates the following error. Under some conditions, errno couldindicate 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 followingconditions:

  • The signal function is being called for a process that is not enabled forasynchronous signals.

  • The signal function is being called when the system signal controls havenot been initialized.

Related Information

  • The <signal.h> file (see HeaderFiles for UNIX-Type Functions)

  • sigaddset()--Add Signal to Signal Set

  • sigdelset()--Delete Signal from Signal Set

  • sigemptyset()--Initialize and Empty SignalSet

  • sigfillset()--Initialize and Fill Signal Set

  • sigismember()--Test for Signal in Signal Set

  • sigprocmask()--Examine and Change BlockedSignals

Example

See Code disclaimer informationfor 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 );
}

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

你可能感兴趣的:(sigpending()--Examine Pending Signals)