Sometimes it happens that a process crashes and takes all the processing power of your machine. In other cases, a process simply overloads the system. It is even possible for malware to consume the entire computer resource. An example of this could be some crypto applications or bloatware. In this article, we’ll look at how to find which processes take the most CPU resources and how to deal with them.
How to find the processes that most utilize the CPU ?
The first thing we can do is use the built-in tool in Linux – top. With its help we can make a list of the processes that take up the most resources.
top -b -d 60 -n 5

From this example we can find the top 5 processes that consume our CPU in this case mysqld with PID 1961.
Another good tool is vmstat it reports information about processes, memory, paging, block IO, traps, and CPU activity.
$ vmstat 1 100
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
r b swpd free buff cache si so bi bo in cs us sy id wa st
0 0 0 288700 17592 1920048 0 0 4482 3297 47 155 8 2 78 12 0
0 0 0 268420 17904 1920584 0 0 788 36 4095 4759 11 3 85 1 0
0 0 0 269916 17940 1920868 0 0 108 560 6969 7280 11 2 86 1 1
3 0 0 267684 18196 1921304 0 0 256 0 5934 6094 9 2 90 0 0
0 0 0 257800 18196 1921528 0 0 0 0 5412 5508 10 1 89 0 1
1 0 0 257368 18196 1922028 0 0 0 0 5852 6046 9 1 89 0 1
0 0 0 256872 18200 1922236 0 0 0 0 5345 5566 9 1 90 0 0
0 0 0 256688 18208 1922292 0 0 0 1788 5388 5602 7 2 90 1 1
0 0 0 256520 18208 1922684 0 0 0 0 5387 5557 8 1 91 0 0
1 0 0 255788 18208 1923024 0 0 0 0 4992 5363 10 1 89 0 1
1 0 0 255392 18208 1923456 0 0 0 0 5027 5145 13 1 86 0 0
0 0 0 254980 18208 1923792 0 0 0 0 5042 5082 21 1 77 0 1
0 0 0 254452 18216 1924092 0 0 0 1848 5481 5695 7 1 91 1 1
0 0 0 254416 18216 1924268 0 0 0 0 4947 5250 7 1 92 0 0
1 0 0 253732 18216 1924616 0 0 0 0 5180 5383 8 2 90 0 1
0 0 0 253584 18216 1924912 0 0 12 0 4464 4623 8 1 91 0 0
0 0 0 243496 18216 1925224 0 0 0 0 5507 5700 9 1 90 0 1
0 0 0 243008 18224 1925504 0 0 0 1356 5070 5345 8 1 90 0 1
1 0 0 243220 18228 1925676 0 0 0 0 6241 6533 11 2 87 0 0
What to do with a process when I find it?
Each case is different, some processes can be restarted, others must be stopped and others can be turned off. The fact that the process loads the system can lead to various things, if it is a database for example you will have to invest in more powerful hardware. If a process is stuck, you will just have to restart it and generally act according to the situation and what the process is.
How to kill a process?
# Kill the PID
kill 1961
Code language: PHP (php)
How to disable a service?
sudo systemctl disable mysql.service
Code language: CSS (css)
How to stop a service?
sudo systemctl stop mysql.service
Code language: CSS (css)
Conclusion
An this article we checked for processes that use large CPU and showed how to kill or disable them. If you know other good practices, please tell us in the comments bellow.
We hope you enjoyed this article. if that is so please rate this page with the stars bellow and subscribe to our YouTube channel or follow us on twiter.