Cover image for Limiting CPU Usage Using CPULimit

Teddy Zugana

Limiting CPU Usage on Linux Processes Using CPULimit. In this tutorial, I will share a little bit about how to limit CPU usage on a process using cpulimit. I myself often use this tool when a process consumes an unreasonable amount of CPU. I once experienced a situation where, while using Burp Suite, the CPU usage on my laptop spiked to 100%. With a utility like cpulimit, it is certainly very helpful.

Install CPULimit
The installation of CPULimit is quite easy. For Debian and Ubuntu users and their derivatives, simply run the command:
Bash

sudo apt install -y cpulimit

Enter fullscreen mode Exit fullscreen mode

Or if you are an RHEL or CentOS user, use yum:
Bash

sudo yum install cpulimit

Enter fullscreen mode Exit fullscreen mode

Make sure you have added the EPEL repository to your RHEL/CentOS system.

Using CPULimit
Monitor CPU usage via htop before cpulimit is run.

Here I want to limit the Burp Suite process, so we filter using grep:
Bash

ps -aux | grep -i burp

Enter fullscreen mode Exit fullscreen mode

Once you find the PID of the target process, run cpulimit with the command:
Bash

sudo cpulimit --pid 150287 --limit 40

Enter fullscreen mode Exit fullscreen mode

Adjust the PID yourself. Here I am limiting the CPU usage for the Burp process to only 40%, so I use the --limit 40 flag. You can adjust it according to your needs.

Now check the resources again using htop or top.

To run cpulimit as a background process, use the --background or -b flag:
Bash

sudo cpulimit --pid 150287 --limit 40 --background

Enter fullscreen mode Exit fullscreen mode

For other available commands, check using:

Bash

cpulimit -h
man cpulimit

Enter fullscreen mode Exit fullscreen mode