When a process misbehaves, you might sometimes want to terminate or kill it. In this post, we'll explore a few ways to terminate a process or an application from the command line as well as from a graphical interface, using gedit[1] as a sample application.
Using the command line/termination characters
Ctrl + C
One problem invoking gedit
from the command line (if you are not using gedit &
) is that it will not free up the prompt, so that shell session is blocked. In such cases, Ctrl+C (the Control key in combination with 'C') comes in handy. That will terminate gedit
and all work will be lost (unless the file was saved). Ctrl+C sends the SIGINT[2]
signal to gedit
. This is a stop signal whose default action is to terminate the process. It instructs the shell to stop gedit
and return to the main loop, and you'll get the prompt back.
Ctrl + Z
This is called a suspend character. It sends a SIGTSTP[3]
signal to process. This is also a stop signal, but the default action is not to kill but to suspend the process.
It will stop (kill/terminate) gedit
and return the shell prompt.
$ gedit
^Z
[1]+ Stopped gedit
$
Once the process is suspended (in this case, gedit
), it is not possible to write or do anything in gedit
. In the background, the process becomes a job. This can be verified by the jobs
command.
$ jobs
[1]+ Stopped