Wednesday, March 10, 2010

How to Limit Linux CPU Usage Per Process

We can use cpulimit program that attempts to limit the cpu usage of a process. Limits are expressed in percentage and not in cpu time. cpulimit 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 INSTALL CPULIMIT
#mkdir /cpulimit
#cd /cpulimit
# wget 'http://downloads.sourceforge.net/cpulimit/cpulimit-1.1.tar.gz'
# tar -zxvf cpulimit-1.1.tar.gz
# cd cpulimit-1.1
# make
# cp cpulimit /usr/local/sbin/
# rm -rf cpulimit*
"gcc" need to be installed
To limit CPU usage of the process called thunderbird to 20%, enter:

# cpulimit -e thunderbird -l 20
# cpulimit -p 1818 -l 20

You can also use absolute path name of the executable, enter:
cpulimit -P /pathto/executablefile -l 20

No comments: