免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1590 | 回复: 2
打印 上一主题 下一主题

请教一个SIGNAL的小问题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-06-23 17:29 |只看该作者 |倒序浏览
如果我已经在一个信号处理函数里面,对于同类型的信号是自动BLOCK的,对吗?我在信号处理函数里面UNBLOCK这个信号,是否可以做到?一但UNBLOCK了,是不是可能造成这个信号处理函数嵌套调用?
呵呵,懒得自己写程序自己试了,请达人帮下忙?

论坛徽章:
0
2 [报告]
发表于 2008-06-23 17:41 |只看该作者
晕,还要自己顶。大概知道什么情况了。

What happens if another signal arrives when your signal handler function is running?

When the handler for a particular signal is invoked, that signal is normally blocked until the handler returns. That means that if two signals of the same kind arrive close together, the second one will be held until the first has been handled. (The handler can explicitly unblock the signal using sigprocmask, if you want to allow more signals of this type to arrive; see section Process Signal Mask.)

However, your handler can still be interrupted by delivery of another kind of signal. To avoid this, you can use the sa_mask member of the action structure passed to sigaction to explicitly specify which signals should be blocked while the signal handler runs. These signals are in addition to the signal for which the handler was invoked, and any other signals that are normally blocked by the process. See section Blocking Signals for a Handler.

Portability Note: Always use sigaction to establish a handler for a signal that you expect to receive asynchronously, if you want your program to work properly on System V Unix. On this system, the handling of a signal whose handler was established with signal automatically sets the signal's action back to SIG_DFL, and the handler must re-establish itself each time it runs. This practice, while inconvenient, does work when signals cannot arrive in succession. However, if another signal can arrive right away, it may arrive before the handler can re-establish itself. Then the second signal would receive the default handling, which could terminate the process.

论坛徽章:
0
3 [报告]
发表于 2008-06-23 23:18 |只看该作者
答案是肯定的,不过一般没有这样的需求
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP