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

0sigpending() wassuccessful.
-1sigpending() 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


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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值