What to do when Ctrl + C can't kill a process?
Solution 1:
To understand the problem of why Ctrl + C does not work, it is very helpful to understand what happens when you press it:
Most shells bind Ctrl + C to "send a SIGINT signal to the program that currently runs in the foreground". You can read about the different signals via man signal:
SIGINT 2 Term Interrupt from keyboard
Programs can ignore that signal, as they can ignore SIGTSTP as well:
SIGTSTP 18,20,24 Stop Stop typed at tty
(Which is what most shells do when you press Ctrl + Z, which is why it is not guaranteed to work.)
There are some signals which can not be ignored by the process: SIGKILL, SIGSTOP and some others. You can send these signals via the kill command. So, to kill your hanging / zombieying process, just find the process ID (PID). For example, use pgrep
or ps
and then kill
it:
% kill -9 PID
Solution 2:
If Ctrl+C (SIGINT) doesn't work, try Ctrl+\ (SIGQUIT). Then try Ctrl+Z (SIGTSTP). If that returns you to a shell prompt, do kill
on the process ID. (This defaults to the SIGTERM signal, which you can specify with kill -TERM
. In some shells, you may be able to use %1
to refer to the PID.) If that doesn't work, go to another terminal or SSH session and do kill
or kill -TERM
on the process ID. Only as a last resort should you do kill -KILL
, a.k.a. kill -9
, as it doesn't give the process any chance to abort cleanly, sync its open files, remove its temporary files, close network connections, etc.
Solution 3:
See this link as well.
Ctrl+Z: pause a process.
Ctrl+C: politely ask the process to shut down now.
Ctrl+\: mercilessly kill the process that is currently in the foreground
Solution 4:
Press Ctrl-Z to suspend the program and put it in the background:
Suspend the program currently running and put it in the background.
This does not stop the process as it does in VMS!
(Restore to foreground again using fg
)
Then, you can kill
or kill -9
it, given its process ID (you get that from ps a
).
Solution 5:
Usually, you can still stop the process (Ctrl + Z) and then use kill -9
. For kill -9
, you need the process PID first. For background jobs, kill -9 %1
is easiest way to do it - if you are unsure what is the number of background job you want to kill, run jobs
.
Alternatively, you can find process ID with
ps
Then you can run
kill -9 <Appropriate PID from ps output>