进程何时处理信号 [英] When does a process handle a signal
问题描述
我想知道linux进程何时处理信号.假设该进程已为信号安装了信号处理程序,我想知道何时中断该进程的正常执行流程并调用信号处理程序.
I want to know when does a linux process handles the signal. Assuming that the process has installed the signal handler for a signal, I wanted to know when would the process's normal execution flow be interrupted and signal handler called.
根据 http://www.tldp.org/LDP/tlk/ipc/ipc.html ,则该过程将从系统调用退出时处理该信号.这意味着像a = b + c(或其等效机器代码)之类的普通指令不会因为信号而中断.
According to http://www.tldp.org/LDP/tlk/ipc/ipc.html, the process would handle the signal when it exits from a system call. This would mean that a normal instruction like a = b+c (or its equivalent machine code) would not be interrupted because of signal.
此外,有些系统调用在收到信号后会中断(并因EINTR失败或重新启动).这意味着即使在系统调用完成之前也要处理信号.这种行为似乎与我在上一段中提到的相冲突.
Also, there are system calls which would get interrupted (and fail with EINTR or get restarted) upon receiving a signal. This means that signal is processed even before the system call completes. This behaviour seems to b conflicting with what I have mentioned in the previous paragraph.
因此,我不清楚何时处理信号以及该进程将在哪些进程状态下进行处理.可以打扰
So, I am not clear as to when is the signal processed and in which process states would it be handled by the process. Can it be interrupted
- 任何时候它都会从内核空间进入用户空间,或者
- 任何时候都在用户空间中,或者
- 任何时候调度程序调度执行该进程
谢谢!
推荐答案
根据 http://www.tldp.org/LDP/tlk/ipc/ipc.html ,则该过程将从系统调用退出时处理该信号.这意味着像a = b + c(或其等效机器代码)之类的普通指令不会因为信号而中断.
According to http://www.tldp.org/LDP/tlk/ipc/ipc.html, the process would handle the signal when it exits from a system call. This would mean that a normal instruction like a = b+c (or its equivalent machine code) would not be interrupted because of signal.
如果是这种情况,那么CPU密集型进程将不会遵循进程调度程序.实际上,调度程序可以在经过其时间范围后的任何时间点中断该进程.除非它是FIFO实时过程.
Well, if that were the case, a CPU-intensive process would not obey the process scheduler. The scheduler, in fact, can interrupt a process at any point of time when its time quantum has elapsed. Unless it is a FIFO real-time process.
一个更正确的定义:将信号传递给进程的一点是控制流离开内核模式以恢复执行用户模式代码时.这不一定涉及系统调用.
A more correct definition: One point when a signal is delivered to the process is when the control flow leaves the kernel mode to resume executing user-mode code. That doesn't necessarily involve a system call.
这篇关于进程何时处理信号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!