信号处理
情况是:我用信号函数注册了一个信号处理程序。 问题:
处理程序是否总是独立于进程状态被调用? (我的意思是它停止了,等等)。那里会发生什么?(取决于状态)
处理程序函数是否被系统注册为一些“特殊函数”(即,当处理程序运行时,未收到其他信号并被放入堆栈或类似的东西中。或者也许它们是如果没有,想象一下,当处理程序 strats 时,进程收到另一个信号,然后再次调用该处理程序,尽管“第一个”尚未完成其任务,依此类推。
The case is: I register a signal handler with signal function.
The question:
Is handler always called independently of the process state? (I mean its stopped, etc.). What happens there?(dependently of the state)
Are handler functions registered as some "special functions" by system (i.e. when handeler runs other signals are not recieved and are put into the stack or smth like that. Or maybe they are simply ignored.) If not, imagine that when handler strats, process gets another signal, then this handler is called again inspite of "the first" hasn't completed its task yet and so on.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
“当进程停止时,在进程继续之前,发送到该进程的任何其他信号都不会被传递,除了
SIGKILL
(...)的默认操作SIGCONT 是在首先处理任何未决的未阻塞信号之后,在进程停止的位置恢复执行。” (Unix 标准,信号概念部分。)
通常,没有什么特别的事情发生。当信号 X 在 Y 的信号处理程序中被捕获时,执行将简单地转移到 X 的处理程序,之后 Y 的处理程序恢复执行。
以下程序演示了这种行为。 raise(sig) 向调用进程发送信号(类似于kill(getpid(), sig))。
这是“安全的”,因为进程只会接受来自具有相同用户 ID(或
root
)的进程的信号,因此您只能搬起石头砸自己的脚。"While a process is stopped, any additional signals that are sent to the process shall not be delivered until the process is continued, except
SIGKILL
(...) The default action forSIGCONT
is to resume execution at the point where the process was stopped, after first handling any pending unblocked signals." (Unix standard, section Signal Concepts.)Ordinarily, nothing special happens. When a signal X is caught while in a signal handler for Y, execution is simply transferred to the handler for X, after which the handler for Y resumes execution.
The following program demonstrates this behavior.
raise(sig)
sends a signal to the calling process (it's likekill(getpid(), sig)
).This is "safe" because a process will accept signals only from processes with the same user ID (or
root
), so you can only shoot yourself in the foot this way.