Chinaunix首页 | 论坛 | 博客
  • 博客访问: 986349
  • 博文数量: 200
  • 博客积分: 5011
  • 博客等级: 大校
  • 技术积分: 2479
  • 用 户 组: 普通用户
  • 注册时间: 2008-06-27 15:07
文章分类

全部博文(200)

文章存档

2009年(12)

2008年(190)

我的朋友

分类:

2008-12-08 12:14:36

10.12 sigprocmask function

#include

 

int sigprocmask(int how, const sigset_t *restrict set,

                sigset_t *restrict oset);

 

Returns: 0 if OK, 1 on error

 

Figure 10.13. Ways to change current signal mask using sigprocmask

how

Description

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.

例子:

Figure 10.14. Print the signal mask for the process

#include "apue.h"

#include

 

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)

        err_sys("sigprocmask error");

    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;

}

 

这个函数主要是用来获得当前进程的singnal mask,以及给当前进程设置mask。注意他不用于多thread环境。当用sigprocmask将一些信号unblock时,如果有pending的信号,那么在sigprocmask返回之前,至少会有一个signal handler被调用。当然不保证在他返回之前所有的pending signal handler都被调用。这也是一个不确定的因素。

Note that SIGKILL and SIGSTOP can't be blocked

阅读(575) | 评论(0) | 转发(0) |
0

上一篇:10.11 signal sets

下一篇:10.13 sigpending function

给主人留下些什么吧!~~