How to Limit The CPU Usage of Any Process in Linux

Have you ever experienced the situation where you open one particular application (such as Firefox) and it brings the whole system to a standstill? If you are running a web server, the last thing that you want to see is to have an application crashes the whole system and bring all the websites down.

Cpulimit is an application for Linux that can limit the CPU usage of a process. It is useful if you want to restrict a particular application from taking up too much CPU resources and thereby crashing the system. This can also be useful when you need to run several intensive programs simultaneously.

Note: cpulimit should work for all Linux distro. In this tutorial, we will be using Ubuntu for illustration.


In Ubuntu, you can install cpulimit via the Ubuntu Software Center, click here to install, or type the following command in terminal:


To restrict a process, use the command

The PID is the process ID of the running application and CPU% is the percentage (0-100, number only) of CPU resources allowed for the app. You can obtain the PID from System -> Administration -> System Monitor .


From the screenshot above, you can see that the Swiftfox application (a variant of Firefox) takes up 68% of the CPU resources before the CPU limit is set. Let’s see what happen when we limit the CPU usage to 20%.



The % CPU instantly drop below 20% and never did it cross the 20% mark again.

Extending cpulimit – Automating the whole process

Cpulimit is useful when you encounter an application that take up lot of CPU resources, or need to carry out batch job. In addition, you can also set it up to monitor the system for any misbehaving application. This is especially useful in a server setup.

abcuser from Ubuntu Forum has come up with a great script that automates the monitoring of your system and restricts any process that exceed a preset CPU limit. The script also allows you to set blacklist/whitelist for specific applications.

Before we start, make sure you have cpulimit and gawk installed.

Download the scripts here. Extract the tar file to your Home folder. You should have two files inside the cpulimit folder: and cpulimit.

Open the file in your text editor (gEdit) and change the following:


CPU_LIMIT: This is the maximum CPU resources available to each application. The default value is 20%.

DAEMON_INTERVAL: This is the interval for the script to check the system. The default is set to 3 seconds.

BLACK_PROCESS_LIST: This contain the list of items that specifically want to monitor. You can use the “|” delimiter to include multiple processes. For example, “mysql|firefox|gedit“.

WHITE_PROCESSES_LIST: This contain the list of items that you DON’T WANT to monitor. You can use the “|” delimiter to include multiple processes. For example, “mysql|firefox|gedit“.

Note: One or both of the variables BLACK_PROCESSES_LIST and WHITE_PROCESSES_LIST has to be empty. You can’t have a blacklist and a whitelist at the same time.

Setting up

Copy the file to the /usr/bin/ folder

Copy the cpulimit file to /etc/init.d/folder, set the necessary permission and make it run during statup.

Now, reboot your system. The cpulimit daemon should start automatically.

You can open a terminal and type:

to check if the cpulimit daemon is running. If it is not running, start it with the command

Alternatively, stop it with:


To uninstall, here’s what you need to do:

1. Stop cpulimit daemon

2. Remove daemon from boot-up procedure

3. Delete boot-up procedure

4. Delete cpulimit daemon

5. Uninstall cpulimit program

Optionally, uninstall gawk program

For more info, refer to the Ubuntu Forum for more detail.

Code credit: abcuser from Ubuntu Forum

Damien Damien

Damien Oh started writing tech articles since 2007 and has over 10 years of experience in the tech industry. He is proficient in Windows, Linux, Mac, Android and iOS, and worked as a part time WordPress Developer. He is currently the owner and Editor-in-Chief of Make Tech Easier.


  1. This is a great utility. I was looking for something like this for quite some time. And the script for creating a monitoring the daemon is an icing on the cake. I’m spreading this article as much as I can

    1. I am glad that you like it. Credit must be given to abcuser from Ubuntu Forum for the script.

  2. Technically speaking, /usr/local/bin is a better place for the script – /usr is where most distributions will install packages to, but /usr/local is reserved for admin-installed things (custom-build packages, admin scripts, etc).

  3. I need the same exact thing for my Windows 2008 server. Do you have similar instructions for that?

Comments are closed.