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:
awill list the processes of all users in the system.
uwill provide additional information like CPU usage, process owner, process state code, etc.
xgets the processes that are not executed from the terminal such as daemons which are started by the system while booting up.
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:
For example, if I want to know the PID of Firefox, I will use the following command:
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:
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):
L (capital) to and it will allow you to locate the string:
For example, here, I searched for SSH:
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:
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:
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:
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:
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.