- 论坛徽章:
- 0
|
The sigpending function returns the set of signals that are blocked from delivery and currently pending for the calling process.
这是UNIX高级环境编程上面的。 前面的或许还可理解(blocked),可后面的pending是什么意思啊 ????
请各位大侠赐教 ! 谢谢 !!!
#include "apue.h"
static void sig_quit(int);
int
main(void)
{
sigset_t newmask, oldmask, pendmask;
if (signal(SIGQUIT, sig_quit) == SIG_ERR)
err_sys("can't catch SIGQUIT");
/*
* Block SIGQUIT and save current signal mask.
*/
sigemptyset(&newmask);
sigaddset(&newmask, SIGQUIT);
if (sigprocmask(SIG_BLOCK, &newmask, &oldmask) < 0)
err_sys("SIG_BLOCK error");
sleep(5); /* SIGQUIT here will remain pending */
if (sigpending(&pendmask) < 0)
err_sys("sigpending error");
if (sigismember(&pendmask, SIGQUIT))
printf("\nSIGQUIT pending\n");
/*
* Reset signal mask which unblocks SIGQUIT.
*/
if (sigprocmask(SIG_SETMASK, &oldmask, NULL) < 0)
err_sys("SIG_SETMASK error");
printf("SIGQUIT unblocked\n");
sleep(5); /* SIGQUIT here will terminate with core file */
exit(0);
}
static void
sig_quit(int signo)
{
printf("caught SIGQUIT\n");
if (signal(SIGQUIT, SIG_DFL) == SIG_ERR)
err_sys("can't reset SIGQUIT");
}
1)当运行时,若没有发出SIGQUIT信号时:
SIGQUIT unblocked
2)当发出SIGQUIT信号时:(在sleep阶段发出信号)
SIGQUIT pending
caught SIGQUIT
SIGQUIT unblocked
为什么这个信号会被捕着到啊? 请各位大侠赐教啊 ! |
|