各位大侠,在APUE(UNIX高级环境编程)信号那一节,有这样一段代码
sigset_t newmask, oldmask;
sigemptyset(&newmask);
sigemptyset(&oldmask);
sigaddset(&newmask, SIGINT);
//block SIGINT and save current signal mask
if(sigprocmask(SIG_BLOCK,&newmaks,&oldmask)<0)
err_sys("SIG_BLOCK error");
//critical region of code
//reset signal mask, which unblocks SIGINT
if(sigprocmask(SIG_SETMASK,&oldmask,NULL)<0)
err_sys("SIG_SETMASK error");
//window is open
pause();//wait for signal to occur
//continue processing
主要是想实现:阻塞某个信号(这儿是SIGINT),然后进程进挂起,至到在这个阻塞信号之前被阻塞的信号发生,处理完毕后,才唤醒进程;书上说sigprocmask和pause之间有一个时间窗口("or if the signal does occur between the unblocking and the pause,we have a problem. Any occurence of the signal in this window of time is lost in the sense that we might not see the signal again, in which case the pause will block indefinitely"), 如果在这个时间
窗口之间发生其它信号,进程会捕捉不到 进程可能被永远挂起,我不能理解,为什么这儿这个时间窗口会导致进程捕获不到其他信号,因为解除对SIGINT阻塞后,一般来说,系统会立即执行SIGINT信号的处理函数,这时发生其它信号,不会被阻塞的呀,只会阻塞SIGINT本身,严重不明白,望各位大侠指教