Skip to main content
How To

How to Kill Process in Ubuntu Command Line

Learn how to find and kill rogue processes using the kill and top commands in Ubuntu.

Sagar Sharma

Have you ever encountered heavy CPU usage while you are doing nothing?

It's probably because there is an unwanted process running in the background that is consuming a hell lot of resources.

And if you know the PID of the process, you can use the kill command in the following manner to instantly kill the process:

sudo kill -9 process_ID

You can use various signals for specific use cases. If not specified, it will use -SIGTERM signal to kill the process (gently).

To learn more about killing signals, I would recommend checking the detailed guide on termination signals.

But there are other ways to accomplish the same thing and that's what I'm going to walk you through in this guide.

How to find and kill the process in Ubuntu

To find a process, you can use various commands.

You can use the ps command to find ongoing processes:

ps aux

Here,

  • a will list the processes of all users in the system.
  • u will provide additional information like CPU usage, process owner, process state code, etc.
  • x gets the processes that are not executed from the terminal such as daemons which are started by the system while booting up.
list ongoing processes in Ubuntu terminal

But when you want to look for a specific process, you should use the pgrep command.

To use the pgrep command to search for a specific process, all you have to do is append the name of the process to the pgrep command:

pgrep process_name

For example, if I want to know the PID of Firefox, I will use the following command:

pgrep firefox
search PID of specific process

Once you know the PID of an unwanted process by using any of the two shown methods, you can use the kill command.

For example, here, I killed the Firefox browser:

kill 3647
kill process in ubuntu using the kill command

How to find and kill processes with the top command

Using top to find and kill processes is quite easy.

First, start the top using the top command (I know you know that):

top

Now, press L (capital) to and it will allow you to locate the string:

search process in top

For example, here, I searched for SSH:

search for specific process in top

For me, the PID is 15482 for SSH.

Once you know the PID, press the k key and enter the PID of the process you want to kill:

enter the PID in top you want to kill

And finally, it will ask you which signal you want to kill the process. I would recommend using the 15 as it is the safest way to kill:

enter the termination single you want to use to kill the process in top

That's it! The process is no longer running.

But if the process is stubborn, you will have to use the other termination signals.

To learn more about termination signals, I would recommend the following guide:

How to use SIGINT and other Termination Signals in Linux
Terminating executing process is more than just kill -9. Here are some of the prominent termination signals and their usage.

Want to kill a process running on a specific Port?

If you want to kill a process running on a specific port, we have a dedicated tutorial for that purpose:

Kill Process Running on a Specific Port in Linux
Want to kill the processes running on specific ports? No need to know the process ID or name. You can terminate a process based on the port number it is using.

I hope you will find this guide helpful.

And if you have suggestions related to what should I cover next or facing any issues while executing shown guide, let me know in the comments.

Sagar Sharma