设置 和 显示 当前进程的signal mask

使用函数sigprocmask()可以设置,和显示当前进程的signal mask。

 

int sigprocmask(int how , const sigset_t *restrict set , sigset_t *restrict oset );

其中的how可以有三中选择。

 

 

SIG_BLOCK

The new signal mask for the process is the union of its current signal mask and the signal set pointed to by set . That is, set contains the additional signals that we want to block.

SIG_UNBLOCK

The new signal mask for the process is the intersection of its current signal mask and the complement of the signal set pointed to by set . That is, set contains the signals that we want to unblock.

SIG_SETMASK

The new signal mask for the process is replaced by the value of the signal set pointed to by set .

 

 

 

 

#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <errno.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/wait.h>
#include <errno.h>
#include <unistd.h>


#define BUFFSIZE 4096

void
pr_mask(const char *str)
{
    sigset_t    sigset;
    int         errno_save;

    errno_save = errno;     /* we can be called by signal handlers */
    if (sigprocmask(0, NULL, &sigset) < 0)
    {
        perror("sigprocmask error");
        return;
    }

    printf("%s", str);
    if (sigismember(&sigset, SIGINT))   printf("SIGINT ");
    if (sigismember(&sigset, SIGQUIT))  printf("SIGQUIT ");
    if (sigismember(&sigset, SIGUSR1))  printf("SIGUSR1 ");
    if (sigismember(&sigset, SIGALRM))  printf("SIGALRM ");

    /* remaining signals can go here */

    printf("/n");
    errno = errno_save;
}


int
main(void)
{
    int    n;
    char   buf[BUFFSIZE];
    sigset_t    sigset;

    sigemptyset(&sigset);
    sigaddset(&sigset, SIGQUIT);
    sigaddset(&sigset, SIGUSR1);
    sigprocmask(SIG_BLOCK,  &sigset, NULL) ;
   
    pr_mask("main: ");

    exit(0);
}
   

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值