免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12
最近访问板块 发新帖
楼主: coconutmm
打印 上一主题 下一主题

linux,阻塞select是否一定能够被SIGUSR1信号中断? [复制链接]

论坛徽章:
0
11 [报告]
发表于 2007-05-18 20:24 |只看该作者
原帖由 flw2 于 2007-5-18 20:16 发表

我很讨厌你

论坛徽章:
0
12 [报告]
发表于 2007-05-18 21:52 |只看该作者
原帖由 coconutmm 于 2007-5-18 20:08 发表
其实,我的意思是说,因为select和上一条语句之间,存在时间窗,也学信号就是在这个时间内发生,对于select存在的信号可能已经丢失了



当然会了, APUE上描述的还是很明确, 我们只能通过sigsuspend解决pause这个问题, 但是select确无法解决. ^^
APUE 10.16:

We test each of the global flags before calling select and again if select returns an interrupted system call error. The problem occurs if either signal is caught between the first two if statements and the subsequent call to select. Signals occurring in here are lost, as indicated by the code comment. The signal handlers are called, and they set the appropriate global variable, but the select never returns (unless some data is ready to be read).

What we would like to be able to do is the following sequence of steps, in order.

Block SIGINT and SIGALRM.

Test the two global variables to see whether either signal has occurred and, if so, handle the condition.

Call select (or any other system function, such as read) and unblock the two signals, as an atomic operation.

The sigsuspend function helps us only if step 3 is a pause operation.

论坛徽章:
0
13 [报告]
发表于 2007-05-24 16:06 |只看该作者
原帖由 coconutmm 于 2007-5-18 20:08 发表
其实,我的意思是说,因为select和上一条语句之间,存在时间窗,也学信号就是在这个时间内发生,对于select存在的信号可能已经丢失了


刚好写了个例子,和你说的情况不知道是一回事么。
大概程序是这样的:
..........
pause();
select();
.......

程序应该阻塞在pause ,还未执行到select,这时程序被usr1信号中断,即函数pause()被中断,如果此时发生了select关心的事件,这个事件是不会丢失的,信号处理函数返回后,执行到select, select能够检测到有事件发生。

论坛徽章:
0
14 [报告]
发表于 2010-03-06 10:48 |只看该作者
pselect()应该能满足楼主的要求
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP