Ctrl+Z or What to do when Ctrl+C doesn’t work

Ctrl+Z or What to do when Ctrl+C doesn’t work

When a process launched become hanged, the most useful option to kill it is to press Ctrl+C, but what to do when Ctrl+C doesn’t work?
In this cases it is very useful to use Ctrl+Z. While Ctrl+C tries to kill the process with the signal SIGINT, Ctrl+Z sends the process to the background, releasing the terminal that was inoperative because the process, and giving us the control again.
Let’s see how to do it using an example. (At the end of the post you can find a video explaining all the process)

To simulate a hang process I am going to launch the python script ignoring_CtrlC.py, that intercept the Ctrl+C signal, making a forever process.

Executing ignoring_CtrlC.py

When I execute the script, and press Ctrl+C this is what happen

CtrlC doesnt work 01

Ctrl+C is not working, instead is displaying a message.

Let’s press now Ctrl+Z and see what happen now

CtrlC doesnt work 02

CtrlC doesnt work 03
The script is now stopped! but still alive at background, it is time to kill it!!

Killing a background process

To kill a background process, we use the command kill, but instead of use the PID of the process, we have to use the background ID, that is indicated between [].

CtrlC doesnt work 04

CtrlC doesnt work 05

Job done!!
The process is killed and the terminal control recovered 🙂

Video explaining all the process

Get CollectNode now !

Leave CollectNode to make the hard work, and spend your time where really matters.

Pin It on Pinterest