信号量问题

hittlle 2009-12-15 04:20:35
各位大侠,在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本身,严重不明白,望各位大侠指教
...全文
84 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
linuhuge 2009-12-15
  • 打赏
  • 举报
回复
作者的意思是
pause 在这是等着有信号中断的。

但如果是在那个时间窗里就已经发生,那么pause是等不来信号从而永远阻塞了

is lost in the sense that we might not see the signal again

这个不是说接收不到信号.
loveisbug 2009-12-15
  • 打赏
  • 举报
回复
回去翻翻书。。
once_and_again 2009-12-15
  • 打赏
  • 举报
回复

不会....
hittlle 2009-12-15
  • 打赏
  • 举报
回复
0回复?伤心。。。。。。

23,125

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 应用程序开发区
社区管理员
  • 应用程序开发区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧