If a linux process is waiting for I/O (i.e it is in SLEEP
state) and a SIGKILL
signal is issued against it, upon termination (STOPPED
state) will it pass through RUNNING
or READY
state?
In other words, for a process to handle a system interrupt such as one generated by SIGKILL
is it necessary to pass through RUNNING
or READY
state ?
Knowing that under normal circumstances a process can handle an interrupt from kernel and knowing that SIGKILL
has a quite contradictory purpose of killing an unresponsive signal, I was doubtful about how much control is given to the process being killed, if any at all.
Signal are "handed off" to a process by the kernel, so sending a signal from processA to processB employs the kernel. When SIGKILL is delivered the kernel does not allow any activity by the process (user mode), specifically process rundown: atexit calls, _exit. Nothing. The process is simply destroyed by the system. This involves some activity in kernel mode. Buffered data is lost. SYSV semaphores and other kernel persistent memory objects are left in memory. It can be a real mess.
If something in kernel memory is causing a hang you use the sysrq interface in linux:
http://tldp.org/HOWTO/Remote-Serial-Console-HOWTO/security-sysrq.html
--to perform whatever semblance of an ordered shutdown you can get.
This is why using SIGKILL is an absolute last resort, because you cannot know what you are breaking. And it will not fix all hangs.
What exactly are you working on?
In addition to jim mcnamara's answer:
SIGKILL (kill -9) cannot be handled.
See the answer at https://stackoverflow.com/a/2541618/1456519 for more.
来源:https://stackoverflow.com/questions/15766036/sigkill-signal-handling