Even a robust operating system like Linux can sometimes encounter problems that cause apps or programs to freeze.
There are several ways to kill or quit a frozen program on Linux. This article will explain how.
Use The Kill Command
Before you can use the kill command, your system needs to know the Process ID (PID) of the unresponsive program.
PID is a number that automatically identifies each process when created on any Linux OS. An advantage of this method is that it works on all Linux systems.
Find The Process & PID
If you don’t know which process is frozen on Linux, two tools will help you find the process: top and ps.
Top is a command line-based system monitor. From the command line, type the following:
The screenshot above shows a lot of information. For example, let’s say Chrome is the frozen program on your computer.
You can see that there are four instances of Chrome that are running with the following PIDs:
To identify the specific instance of Chrome you want to kill, use the ps command and grep to filter the output.
The command below will show you the running processes associated with Chrome:
ps aux | grep chrome
Kill The Process
You now have the two pieces of information needed to kill a frozen process on Linux: its name and ID. Use the commands below:
- kill – Kill a process by ID
- killall – Kill a process by name
There are other signals you can send to both commands, depending upon the results you want.
As an example, if you want to kill the unresponsive process and then restart it, you will use the HUP (hang up) signal.
Other kill signals include:
- SIGSTOP to stop the process
- SIGNINT to interrupt the keyboard
- SIGKILL to kill the signal
We learned from the ps command above that the PIDs for the instances of Chrome are 3827, 3919, 10764, and 11679.
To send the kill signal, run the following commands to kill all four instances of Chrome successfully:
- kill -9 3827
- kill -9 3919
- kill -9 10764
- kill -9 11679
You can also use the single command below using killall to send the same signal:
killall -9 chrome
Click The X
Unresponsive programs and apps typically have grayed-out buttons or options that don’t work. Sometimes you can’t even move the app window around the screen.
The easiest solution is to click the X button in the top corner. Depending upon your OS, the button may be on the left or on the right top corner.
After clicking the X, you will see a dialog box with two options: Wait or Force Quit. To end the program, click Force Quit.
Kill a Linux Process on Linux Using System Monitor
The default System monitor in Ubuntu is called Gnome. It gives insights into all the processes running on Ubuntu Linux operating systems.
Users can perform various tasks using the Graphical User Interface (GUI), including Stop, Continue, and Kill.
If your system doesn’t include the Gnome system monitor app, install it by following the steps below. This process works for all active versions of Ubuntu Linux as well as Linux Mint and Debian.
- Use the Terminal keyboard shortcut CTRL+ALT+T. Then use the command below to download and install the Gnome System monitor.
sudo apt-get install gnome-system-monitor
- Open system monitor using Command Terminal with the following:
- Or, using the GUI, navigate to Applications, type system monitor in the search box, and click on the icon to open it.
- Open your System Monitor, browse the Processes column to find the unresponsive or frozen program, select and right-click on it.
You will see several options, including:
- End Process to terminate the application while cleaning temporary files.
- Stop Process to pause the process enabling you to continue working with it later.
- Kill Process is the most extreme of the options and will work to quit a frozen program if trying to end it doesn’t work
Use The xkill Command
Xkill is a pre-installed Ubuntu kill utility that you can use to force kill an unresponsive Linux process. It is a tool that comes pre-installed in Ubuntu.
You can also install it via the Terminal on other distributions by using the following command:
sudo apt install xorg-xkill
Then run it by typing xkill. Your mouse will turn into a skull or an x. Left-click on the frozen program to close it.
Use pgrep & pkill
Several Linux systems offer shortcuts called pkill and pgrep for performing the same tasks as kill and ps discussed above.
Pgrep will show the process name and ID. For example, running pgrep chrome to see the process ID of the running Chrome process. You can then use that ID with the kill command.
Or, you can skip this step and use the command below to kill all instances of Chrome:
This solution works well if you only have one instance of an application running. However, if you have several windows open of the same program and only want to kill one, use XKill instead.
When a program hangs, restarting your system is not always the most convenient option. This is especially true if you are working on several projects at the same time and have not saved your work.
Try one of the options above as an alternative to easily and quickly exit frozen or non-responsive programs on Linux safely.