Kill a process that won't respond to CTRL+C
Sometimes a process gets stuck and how often you try, it won’t respond to the combination of CTRL+C. One option is to open a second shell, then perform a kill.
kill 1234
Pushing a job to the background
While this works, there is usually a much easier way. This involves pushing a running process into the background by pressing CTRL+Z.
[1]+ Stopped ./runserver
Kill the process
To get it back to the foreground, we would normally run fg
. Instead, we tell it to stop.
kill %1
The %1 refers to the first process that is in the background, noted by the [1] in the output above. After running the kill command, we see the following output:
[1]+ Stopped ./runserver
It is typically showing the same output, but this time the process received a kill signal. When you put multiple processes to the background, it would make sense to first check the output of the jobs
command. It will show any job that is running, including those that are pushed to the background and no longer visible on screen.
Jobs option | Explanation |
---|---|
-l | Show process ID (PID) |
-n | Only show those processes that have a changed status since last run of jobs |
-p | Show PID only |
-r | Only show running jobs |
-s | Only show stopped jobs |
Do you have another great tip to deal with processes? Let it know!