Shell – Why doesn’t SIGKILL terminate a stopped program (yes)

job-controlshell

I'm using Ubuntu 14.04 and I'm experiencing this behavior I can't seem to understand:

  1. Run the yes command (in the default shell: Bash)
  2. Type CtrlZ to stop yes
  3. Run jobs. Output:
    [1]+ Stopped yes
  4. Run kill -9 %1 to stop yes. Output:
    [1]+ Stopped yes
  5. Run jobs. Output:
    [1]+ Stopped yes

This is on Ubuntu 3.16.0-30-generic running in a parallels virtual machine.

Why didn't my kill -9 command terminate the yes command? I thought SIGKILL can't be caught or ignored? And how can I terminate the yes command?

Best Answer

Signals are blocked for suspended processes. In a terminal:

$ yes
...
y
y
^Zy

[1]+  Stopped                 yes

In a second terminal:

$ killall yes

In the first terminal:

$ jobs
[1]+  Stopped                 yes

$ fg
yes
Terminated

However SIGKILL can't be blocked. Doing the same thing with killall -9 yes from the second terminal immediately gives this in the yes terminal:

[1]+  Killed                  yes

Consequently if kill -9 %1 doesn't terminate the process right away then either bash isn't actually sending the signal until you fg the process, or you have uncovered a bug in kernel.

Related Question