How to Limit the application CPU usage in Linux (CPUlimit)
CPULimit is a simple program to limit the CPU usage of certain application in Linux. It’s reside in the Ubuntu repositories by default. We can install it by issue the following command in Ubuntu
sudo apt-get install cpulimit
Output
mkyong@mkyong:~$ sudo apt-get install cpulimit
[sudo] password for mkyong:
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
linux-headers-2.6.28-11 linux-headers-2.6.28-11-generic
Use 'apt-get autoremove' to remove them.
The following NEW packages will be installed:
cpulimit
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 9730B of archives.
After this operation, 65.5kB of additional disk space will be used.
Get:1 http://my.archive.ubuntu.com jaunty/universe cpulimit 1.1-11 [9730B]
Fetched 9730B in 1s (8940B/s)
Selecting previously deselected package cpulimit.
(Reading database ... 131942 files and directories currently installed.)
Unpacking cpulimit (from .../cpulimit_1.1-11_i386.deb) ...
Processing triggers for man-db ...
Setting up cpulimit (1.1-11) ...
mkyong@mkyong:~$
We can limit the application CPU usage either by executable name or process id (pid). For example, we have a cron job written in python (name = mycronjob.py , pid = 1234)
Limit the process ‘mycronjob.py’ by executable name to 50% CPU usage
cpulimit -e mycronjob.py -l 50
Limit a process by PID (1234) to 50% CPU:
cpulimit -p 1234 -l 50
This is quite useful program to prevent certain application to used all our CPU usage 🙂
About Author
Comments
Subscribe
0 Comments