Ubuntu / Linux news and application reviews.





cpulimit is a simple program that attempts to limit the cpu usage of a process (expressed in percentage, not in cpu time). This is useful to control batch jobs, when you don't want them to eat too much cpu. It does not act on the nice value or other scheduling priority stuff, but on the real cpu usage. Also, it is able to adapt itself to the overall system load, dynamically and quickly.

To use cpulimit, first download it then extract the archive, use the terminal to navigate to it's folder and:
make
cp cpulimit /usr/local/sbin/
rm -rf cpulimit*
Ubuntu users: all you have to do is open a terminal and type this:
sudo apt-get install cpulimit

cpulimit examples:

Limit the process 'bigloop' by executable name to 40% CPU:
cpulimit -e bigloop -l 40
cpulimit -e /usr/local/bin/bigloop -l 40
So for Firefox, you would have to:
cpulimit -e firefox -l 40
Limit a process by PID to 55% CPU:
cpulimit -p 2960 -l 55
Launch a process by command line and limit it to 40% (in development version only!):
cpulimit -l 40 /etc/rc.d/rc.boinc start

To find out the pid of an application, simply type this in a terminal:

-for all applications running:
ps -e
-for a specific application (for example Firefox):
pidof firefox
(you may also want to check out our list of 20 great Linux terminal commands)


Notes

If your machine has one processor you can limit the percentage from 0% to 100%, which means that if you set for example 50%, your process cannot use more than 500 ms of cpu time for each second. But if your machine has four processors, percentage may vary from 0% to 400%, so setting the limit to 200% means to use no more than half of the available power. In any case, the percentage is the same of what you see when you run top.

cpulimit should run at least with the same user running the controlled process. But it is much better if you run cpulimit as root, in order to have a higher priority and a more precise control.
Now cpulimit does limit also the children of the specified process. The code is still experimental, so let me know how it is.

[via ciberciti]