分类:
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. |
例子:
#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