SIGKILL signal handling

人走茶凉 提交于 2019-11-29 21:26:01

问题


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.


回答1:


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?




回答2:


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!