Managing Linux processes is one of the skills that any Linux user or sysadmin should have at their fingertips. Part of this skill set involves killing undesirable processes. This guide takes you through how you can find and kill a running process on your Linux system. We have used Ubuntu 20.04 for demonstration purposes.
What is a process?
A good place to start is to pose this question; What is a process? A process is an instance of a running application or command. The Linux operating system tracks a process using a PID (Process ID). A PID is unique to a process.
Types of processes
Fundamentally, Linux processes can be classified into two: Foreground and background processes. Let’s briefly go over each of these.
These are synonymously known as interactive processes. A foreground process is one that is initialized or spawned using a terminal by a logged-in user. Simply out, foreground processes are started by users when they input commands on the terminal shell. They do not start automatically.
Background processes are quite the opposite of foreground processes. They are referred to as non-interactive processes and require no keyboard input. In short, no user intervention is required to start a background process.
How to kill a process in Linux
Occasionally, you may need to kill or end unresponsive processes or processes which are gobbling up system resources. The best approach is to use the terminal which comes with an array of command-line tools to help you find and kill unwanted processes.
When you launch an application, some processes are initiated in the background. If the application becomes unresponsive or slow for one reason or the other, you can forcefully close it by killing the process associated or linked to it.
Before you kill a process, you must first identify its PID or Process ID. They are many ways of obtaining the PID of a process. Let’s explore.
How to find the PID of a process or program
One of the easiest ways of unearthing the PID of a process is using the pidof command-line tool.
If you already know the program’s name, then use the command syntax below to obtain its PID:
$ pidof program_name
For example, to find out all the processes initiated by the Firefox browser, run the command:
$ pidof firefox
If you are not certain of the name of the program, run the Linux ps command as shown.
$ ps -aux | grep -i application_name
Now let’s see how you can terminate the processes using the PID.
How to kill a running process using the PID
$ sudo kill -9 PID
If the program has multiple running processes, simply list all the PIDs in one line as follows.
$ sudo kill -9 PID_1 PID_2 PID_3
In our example, this translates to
$ sudo kill -9 10528 10220 10460 10437 10406
This approach can be a bit tedious and time-consuming. A better way of killing all processes is by using the awesome killall command followed by the name of the application. This terminates all processes associated with the program.
$ sudo killall name_of_program
In our case to kill all processes associated with the Firefox browser, execute the command:
$ sudo killall firefox
If you have been having an arduous time trying to terminate processes or programs, our hope is that this guide has shed enough light on how to go about it. We trust you can comfortably find and kill running process on a Linux system.
Karim Buzdar holds a degree in telecommunication engineering and holds several sysadmin certifications including CCNA RS, SCP, and ACE. As an IT engineer and technical author, he writes for various websites.