日期:2014-05-16 浏览次数:20702 次
5 #include"apue.h" 6 static void sig_quit(int); 7 8 int main(void) 9 { 10 sigset_t newmask,oldmask,pendmask; 11 12 if(signal(SIGQUIT,sig_quit) == SIG_ERR) 13 err_sys("can't catch SIGQUIT"); 14 15 sigemptyset(&newmask); 16 sigaddset(&newmask,SIGQUIT); 17 18 if(sigprocmask(SIG_BLOCK, &newmask, &oldmask) < 0) 19 err_sys("SIG_BLOCK error"); 20 21 sleep(5); 22 23 if(sigpending(&pendmask) < 0) 24 err_sys("sigpending error"); 25 if(sigismember(&pendmask, SIGQUIT)) 26 printf("\nSIGQUIT pending\n"); 27 28 if(sigprocmask(SIG_SETMASK, &oldmask, NULL) <0) 29 err_sys("SIG_SETMASK error"); 30 printf("SIGQUIT unblocked\n"); 31 sleep(5); 32 exit(0); 33 } 34 static void sig_quit(int signo) 35 { 36 printf("caught SIGQUIT\n"); 37 if(signal(SIGQUIT, SIG_DFL) == SIG_ERR) 38 err_sys("can't reset SIGQUIT"); 39 } ~