How To Kill A Process On Ubuntu Using The Command Line
How do you kill a process on the Ubuntu operating system using the command line?
To kill a process, you need to first find the ID of the process you want to kill and then kill it using the
kill -9 PID or
killall APP_NAME command.
In this article, we'll show you some ways to locate a process PID and how to kill the process with the
Let's get started!
Table of Contents
Locate The Process PID
Later on this article, you'll see that you can kill a process by using its unique name or process ID (PID). The PID is the unique identifier given to each process that is running on your machine at any given time.
Before you can kill a process on Ubuntu, you need to locate the PID of the process you wish to get rid of. In this section, we'll show you three ways to find your PID.
If you already have a PID, you can skip to the killing section.
Method 1 - Top Command
top program provides a real-time view of all the processes running on your system. It can display both a summary of your system and a list of all the tasks currently running.
To run the program, open a terminal window (
T) and execute this command:
The output in your terminal will look similar to the image below.
As you can see, the PID for each process is listed on the far left-hand side of the table.
You can scroll through the table with the
down arrows on your keyboard.
Method 2 - Ps & Grep Commands
The second method to find a PID is to use the
In your terminal, type in this command:
ps (process statuses) command displays information about the processes running on your system. And with
aux attached to it, it will show running processes for all the users on your machine.
The output will look similar to the image below.
Notice that process ID is listed in the PID column of the table.
And you can also filter the list down using the
grep command. For example, if you wanted to find the process associated with the VLC media player, you could use this command:
ps aux | grep -i vlc
This will output info on any of the processes currently running VLC on your machine. The output will look similar to this:
username 20296 0.2 0.3 1243700 63276 ? Sl 19:51 0:00 /usr/bin/vlc --started-from-file
Let's go over one more method of getting a PID.
Method 3 - Pidof Command
The last method we'll go over is the
pidof finds the process id's for any of the named programs and prints the id's to the command line.
You can use the command like this:
If processes are running on your system with that name, a list of PIDs will be logged:
7394 6894 4587
If there aren't any processes with that name, nothing will be returned.
Kill The Process Using The PID
When you have the process ID, you can move on to killing the application using that PID and the
kill -9 PID command.
Here is what the command looks like (use your PID):
sudo kill -9 PID
That will completely kill the application running on that specific process.
sudo, you will be able to kill any process being used by any user on your machine. Without
sudo, you can only kill processes being used by the current user.
Another method for killing a process is the
killall command. This command will kill any application with the information you pass to the command.
Here is an example of how to kill an application with a given name:
sudo killall vlc
That command ends any process with the name of