Linux

Limit CPU Usage Of A Process In Linux

Limit CPU Usage Of A Process In Linux

In this tutorial post, we are going to see the method to limit CPU usage of a process in Linux which means that we are going to stop the process which consume more CPU usage.

Tutorial To Limit CPU Usage Of A Process In Linux

To limit CPU usage of a process in Linux, we will using third party application known as a CPULimit.

Let’s install CPU Limit at first in various Linux distributions.

Install CPU Limit On Ubuntu ( Debian/Linux Mint):

$ sudo apt-get install cpulimit

Install CPULimit On SUSE/openSUSE:

$ sudo zypper install cpulimit

Install CPULimit On Arch Linux:

$ sudo pacman -S cpulimit

Install CPULimit On RHEL/Fedora/CentOS:

You need to enable EPEL repository first.

$ sudo yum install epel-release

And then, install CPUlimit using command:

$ sudo yum install cpulimit

Or,

$ sudo dnf install cpulimit

After installing CPULimit, It’s time to view how much CPU the process is consuming or check the process using high CPU usage. Run the following command to check:

$ top

You will see the output with various process and it’s detail. You will see something like this

PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND                    
 2650 root      20   0    7554    806    520 R 100.0  0.1   0:40.03 omgfoss.sh                         
 2651 root      20   0   22950   1706   1180 R   0.3  0.2   0:00.08 top 

In above output, omgfoss.sh is using almost all CPU resource. Process Id of the omgfoss.sh is 2650. We are going to limit the CPU usage to 28%.

Use CPULimit tool to control or limit the CPU usage of the process using  high CPU resource. Run the following command in your terminal to limit the CPU usage of process:

$ cpulimit -l 28 -p 2650 &

 

READ THIS ALSO  Grep Command Tutorial In Linux | Beginner's Guide

Note: “-l 28” limits the process to 28%.

 Let us know if there is any error in  this post.

 



Subscribe To Our Newsletter.

Join our mailing list to receive the latest linux tutorials, tips & tricks, freebies,news and updates from our team.

You have Successfully Subscribed!