Find and Kill Running Processes in Ubuntu 20.04 Linux System - How to do this ?

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.

Basically, It often happens that you need to ‘kill’ an unresponsive program.

In Windows you have the task manager for this situation. 

You can use task manager in Linux as well but the command line way is a lot better and effective in handling unresponsive programs.

Here at LinuxAPT, as part of our Server Management Services, we regularly help our Customers to perform related Ubuntu Linux System queries.

In this context, we shall look into how you can find and kill a running process on your Ubuntu Linux system. 


What is a Process in Linux ?

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.


i. Foreground processes

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.


ii. Background processes

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 ?

Sometimes, 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.


1. 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.


2. How to kill a running process using the PID ?

Execute the command below to kill a running process with a 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


[Need urgent assistance in fixing Missing Software Packages on Ubuntu Linux Systems? We can help you. ]

This article covers method to comfortably find and kill running process on a Linux system.

If you run an application, it runs some process in the background. If you want to close this application forcefully, you can kill the process associated to it.

To kill a process, you need to know the its process ID (PID). The next section tells you how to find the process ID of a program.


To Kill the process using the PID

1. Once you have the PID of the desired application, use the following command to kill the process:

$ sudo kill -9 process_id

2. If you have more than one process id, you can kill all of them together by providing all the PIDs.

$ sudo kill -9 process_id_1 process_id_2 process_id_3

Related Posts