sigpending函數返回信號集,其中的各個信號對于調用進程是阻塞的而不能遞送,因而也一定是當前未決的。該信號集通過set參數返回。(這些信號是已經產生的信號,但因為信號屏蔽字中對其設置了屏蔽位,從而被阻塞,不能遞送給進程的那些信號。注意sigpending返回的信號集與信號屏蔽字的區別。從集合角度來講,此信號集是當前信號屏蔽字的子集。)
#include <signal.h>int sigpending(sigset_t *set);返回值:若成功則返回0,若出錯則返回-1
程序清單10-11 信號設置和sigPRocmask實例
#include "apue.h"static void sig_quit(int);intmain(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 voidsig_quit(int signo){ printf("caught SIGQUIT/n"); if (signal(SIGQUIT, SIG_DFL) == SIG_ERR) err_sys("can't reset SIGQUIT");}
本篇博文內容摘自《UNIX環境高級編程》(第二版),僅作個人學習記錄所用。關于本書可參考:http://www.apuebook.com/。
新聞熱點
疑難解答