#include "apue.h"
static void sig_quit(int);
int main()
{
sigset_t newmask, oldmask, pendmask;
if (signal(SIGQUIT, sig_quit) == SIG_ERR)
err_sys("can't catch SIGQUIT");
sigemptyset(&newmask);
sigaddset(&newmask, SIGQUIT - 1);
if (sigprocmask(SIG_BLOCK, &newmask, &oldmask) < 0)
err_sys("SIG_BLOCK error");
sleep(5);
if (sigpending(&pendmask) < 0)
err_sys("sigpending error");
if (sigismember(&pendmask, SIGQUIT - 1) < 0)
printf("\nSIGQUIT pending\n");
if (sigprocmask(SIG_SETMASK, &oldmask, NULL) < 0)
err_sys("SIG_SETMASK error");
printf("SIGQUIT unblocked\n");
sleep(5);
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");
}
按书本说,运行时,第一次休眠5秒钟时,按下ctrl+\输出结果是
SIGQUIT pending
catch SIGQUIT
SIGQUIT unblocked
但是我的运行结果没有输出SIGQUIT pending,即
catch SIGQUIT
SIGQUIT unblocked
这是什么原因呢?
shampoo 于 2009-11-13 15:38:28发表:
哇!狂顶!
写得有够长,呵呵。
tkfly0324 于 2009-11-13 15:05:14发表:
顶
tkfly0324 于 2009-11-13 15:05:08发表:
顶