如果UNIX的信号处理过程中,同样的信号被发送到程序会发生什么? [英] What happens if during a signal handling in UNIX, the same signal gets sent to the program?

查看:162
本文介绍了如果UNIX的信号处理过程中,同样的信号被发送到程序会发生什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在这个任何想法?是否有某种信号队列,或者它掉下来?

Any ideas on this? Is there some kind of a signal queue, or does it get dropped?

虽然我们在这个问题,这是真的,信号处理应该做的最小的工作尽可能?

While we are at this question, is it true that signal handlers should do as minimal work as possible?

我读的地方,信号处理程序应使用管道和只写一个字节给它,表示该方案应该做的事情。然后别处程序定期检查管,并根据在其字节调度。 (我可能误会了吧)

I read somewhere that a signal handler should use a pipe and just write one byte to it, indicating what the program should do. Then somewhere else the program periodically checks the pipe, and dispatches based on byte in it. (I might have misunderstood it)

谢谢,博大Cydo。

推荐答案

要回答你的问题的第二部分,这是真的,信号处理应该做的最小的工作尽可能?答案是肯定的,因为有一组是异步信号安全,因此能够从信号处理程序调用的函数很小。异步信号安全是一种重入的增强形式。如果富()是异步信号安全的,这意味着它是安全的富()信号处理程序中调用,即使富()当信号被提出已经执行。

To answer the second part of your question, "is it true that signal handlers should do as minimal work as possible?" the answer is yes, because there is a very minimal set of functions that are "async signal safe" and therefore able to be called from signal handlers. Async signal safety is kind of an enhanced form of re-entrancy. If foo() is async signal safe, that means that it's safe to call foo() within a signal handler, even if foo() was already executing when the signal was raised.

您可以通过看,对于信号一节7手册页人7信号)。从信号处理程序中调用比这些之外的任何功能,直接或间接地调用未定义的行为。

You can get the full list of async signal safe functions by looking that the section 7 man page for signal (man 7 signal). Calling any function other than one of these from within a signal handler, directly or indirectly, invokes undefined behavior.

写到管道字节的方法来处理信号,而不只限于异步信号安全功能,特别是如果你的程序是围绕一个选择循环。

The "write a byte to a pipe" approach is a great way to deal with signals without being restricted to async signal safe functions, especially if your program is already oriented around a select loop.

这篇关于如果UNIX的信号处理过程中,同样的信号被发送到程序会发生什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆