SIGKILL signal handling
Asked Answered
S

2

8

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.

Seavir answered 2/4, 2013 at 13:57 Comment(1)
SIGKILL is an unfortunate example as it is a signal which can't be handled by the receiving process. If your question is unrelated to SIGKILL and it is a mere example, consider using another signal to express what you mean.Delegation
B
10

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?

Boynton answered 2/4, 2013 at 14:32 Comment(5)
I don't think the OP's question was specific to SIGKILL. I understand it rather as "does a process need to be active to handle a signal".Delegation
A process has to have cpu context to receive signals. SIGKILL is slightly different. Processes have two components - kernel -- sometimes called P0, user land code, call it P1. P0 and P1 are simply returned to paged pool non-paged pool and to system memory when SIGKILL is picked up by the kernel. Some things like semaphores stay in kernel memory. So in this sense P1 never does become active. You definitely could argue that some P0 activity is in process context, but your user mode code cannot do anything about it.Boynton
Yes, I know that and your post already says that SIGKILL can't be handled. But I don't think that the OP is asking for SIGKILL but all signals in general. So, your first sentence of your comment is the answer to the OP's question IMO.Delegation
A kernel-only process ( a zombie for example) cannot receive a signal, because it does not poll for them. So there is nothing to SIGKILL, anyway. Maybe this is the source of confusion. The kernel "part" does stuff, the user land part does not do "stuff"Boynton
@Delegation - The answer to that is the process has to be able to poll for signals, which means it has to have process context. It has to be able to access the cpu. True for all signals.Boynton
S
2

In addition to jim mcnamara's answer:

SIGKILL (kill -9) cannot be handled.

See the answer at https://mcmap.net/q/130321/-how-to-gracefully-handle-the-sigkill-signal-in-java for more.

Sixteenth answered 2/4, 2013 at 15:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.