What to do when Ctrl + C can't kill a process?

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

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.


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

Tags:

Linux

Shell

Bash