Before diving into the guide, consider exploring some ways to quickly access the Terminal on Linux for swiftly opening this command-line interface window.
Utilize the Pkill command to terminate programs on Linux, Ubuntu effectively.
The simplest way to quickly terminate programs on Linux, Ubuntu via Terminal is by using the Pkill command. Pkill command proves quite handy, eliminating the necessity for average users to know specific process ID numbers. Instead, you can end a process by inputting its name.
Below is a specific example of the pkill command:
pkill firefox
Most users simply need to execute the pkill command without requiring root user privileges to terminate a process or unresponsive frozen programs. However, this command isn't always helpful. This holds particularly true if you need to kill a program running under root user privileges, or if it's your own program. In this case, you'll have to use the sudo command along with it:
sudo kill rootprogram
However, merely using the pkill tool to terminate a root program might not suffice. Sometimes, simply killing commands won't be of much help. In such cases, you can append -9 to the end of the kill command to forcefully terminate the program if other options fail.
sudo pkill -9 rootprogram
Using the Pidof and Kill commands to terminate programs on Linux, Ubuntu
In case the Pkill command fails, you can opt for the Kill command as an alternative. Essentially, the Kill command operates similarly to the Pkill command, except that it works based on the Process ID rather than the program name (like pkill firefox, ...).
One limitation when killing programs with the kill command is that you need to find out if there are any issues with the Process ID of the program before using the command. To check the Process ID of a program, you use the pidof command. Here's how the pidof command works:
pidof firefox
Once pidof completes the process of finding the exact ID, the Terminal window will display the output. For example:
pidof firefox
OUTPUT: 2219
You can utilize Process ID 2219 to terminate Firefox:
kill 2219
Note that if you want to terminate a root program, you use the following command:
sudo kill 2219
Finally, if the application refuses to terminate, you append -9 after the kill command, similar to the pkill command:
sudo kill -9 2219
Terminate programs on Linux, Ubuntu using the Htop command
If you prefer not to use individual commands to terminate unresponsive programs on Linux, Ubuntu, you might consider installing Htop. Similar to the Pkill and Kill commands, you can use this tool remotely or via SSH.
As it runs in the Terminal window, Htop can terminate unresponsive programs on the system. Developed and enhanced based on the TOP system management tool, which comes pre-installed on most Linux systems, Htop incorporates numerous new improvements such as graphical card, better CPU/RAM display, and processes.
Additionally, Htop allows users to scroll horizontally/vertically without disrupting the tool, enabling users to terminate processes without needing to know their process ID and includes various methods to terminate everything.
Note: Htop requires Ncurses to function properly. Install 'ncurses' by searching in the package manager of your Linux distribution (in case Htop doesn't have Ncurses installed).
Install Htop
To install Htop on various Linux distributions, you can use the following commands:
- On Ubuntu:
sudo apt install htop
- On Debian:
sudo apt-get install htop
- On Arch Linux:
sudo pacman -S htop
- On Fedora:
sudo dnf install htop
- On OpenSUSE:
sudo zypper install htop
- On other Linux distributions:
To install the latest version of Htop for your Linux distribution, open Terminal and use the package manager to install Htop. Suppose for some reason you can't find Htop, visit the official website to download the source code and build Htop for yourself.
Using Htop
Open the Htop tool by opening a Terminal window and typing Htop into it. Additionally, you can run the Htop tool anytime by searching for Htop in the application menu. Or you can use shortcuts to open Htop.
Once Htop is open, use the arrow keys to select the process you want to terminate. Press F9 key to open the kill menu. Use F6 key to sort processes, and F3 key to search for running programs. If you need help with the Htop tool, press F1 key to open the help menu. Or you can type 'man htop' into the Terminal window.
Finally, to exit the Htop tool, simply press Q key on the keyboard, or you can use F10 key to exit the tool.
So, in the article on Mytour, we just guided you through 3 ways to terminate programs on Linux, Ubuntu via Terminal. Suppose in the future if you encounter situations where programs, applications become unresponsive on Linux, Ubuntu, you can use the methods above to terminate the programs.
Additionally, if you force kill programs in the Terminal, the data you are working on may be lost. With the browser, you can restore tabs, but for other programs, it depends on the built-in recovery mechanism of the program.