Limit CPU usage of Process in Ubuntu

Sometimes, a Process pushes itself to the limit making the machine unusable. So, we thought of making this article today to deal with that issue. There are ways in Ubuntu which can help us limit CPU usage of a process. We are just deliberately pushing the process to go slow.

The package that can help us achieve it is cpulimit. It is worth mentioning here that, it doesn’t impacts the nice value. If you would like to know more about nice values.

We first cover the installation steps required for the package – cpulimit.

Note: Following operations would require you to have superuser privileges. In case you don’t have one then we advise you to contact your System Administrator for assistance.

Install cpulimit in Ubuntu

Since the package is already available through standard Ubuntu repository. Therefore, we recommend you to update the repository first. This ensures we get to have the latest version of the package. Hence, open a terminal and issue the following –

sudo apt update

Next, to install cpulimit

sudo apt install cpulimit

Now, we focus on limiting the process which is consuming way too many resources.

Limit CPU usage of Process in Ubuntu

To use cpulimit, first look for the Process ID of the process we want to limit. There are various methods to find Process ID, we prefer to use htop. If it isn’t there then use following code to install it –

sudo apt install htop

And, issue the following in terminal –

htop

To search for a process, Press F3. And, write the name of the process we want to search. For instance, if its was atril. Then, write atril and press Enter. It would highlight the process atril. In the first column of htop utility, we get the Process ID. Note it down somewhere. Let’s say PID assigned to atril was 7997.

It is worth mentioning here that, a different Process ID is assigned every time we launch an application.

Now, to limit the CPU usage (in percentage) of a Process –

cpulimit -p [PID] -l [limit_in_percentage]

For instance,

cpulimit -p 7997 -l 50

This would reduce the CPU usage for the Process – atril to half.

Alternately, if you know the exact process name then use –

cpulimit -e [Process_name] -l [limit_in_percentage]

For instance,

cpulimit -e firefox -l 10

In conclusion, we have covered how to limit CPU usage of a Process in Ubuntu.

Similar Posts