To install in ubuntu:
$ sudo apt-get install cpulimit
It is in the universe repositories.
To install it on any other Linux distribution follow this:
$ wget http://downloads.sourceforge.net/cpulimit/cpulimit-1.1.tar.gz
$ tar-zxf cpulimit * xxx.tar.gz
$ cd cpulimit-xxx
To use it, you will need to know the name of the application or PID, once you know it:
Examples of use
If we want to avoid that Firefox does not exceed 30% of CPU usage type
cpulimit -e firefox -l 30
In the case of wanting to limit the process with PID 3675 to use only 40% CPU at maximum, for that type on your console as follows:
cpulimit-p 3675-l 40
You can also add the full path of your application:
cpulimit-P / l usr/lib/firefox-3.0.11/firefox-30
Limit the process ‘bigloop’ by executable name to 40% CPU:
cpulimit –exe bigloop –limit 40
cpulimit –exe /usr/local/bin/bigloop –limit 40
Limit a process by PID to 55% CPU:
cpulimit –pid 2960 –limit 55
Launch a process by command line and limit it to 40% (in development version only!):
cpulimit –limit 40 /etc/rc.d/rc.boinc start
cpulimit -e applicationname -l 30 o cpulimit -p PID -l 40
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.
Official Website: CPU Limit