You can use “cpulimit” program that can limit the CPU usage for a particular process. Follow the process below to set a limit for CPU usage.
Install cpulimit
Type the following commands to install “cpulimit”:
# cd /tmp
# 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*
Debian / Ubuntu Linux users
Type the following command to install “cpulimit”:
$ sudo apt-get update
$ sudo apt-get install cpulimit
How do I use cpulimit?
To limit CPU usage of the process called firefox to 30%, enter:
# cpulimit -e gzip -l 30
To limit CPU usage of the process to 30% by using its PID, enter:
# cpulimit -p 1313 -l 30
To find out PID of the process use any of the following:
# ps aux | less
# ps aux | grep gzip
# pgrep -u php php-cgi
# pgrep gzip
You can also use absolute path name of the executable, enter:
# cpulimit -P /bin/gzip -l 30
Parameter:
- -p : Process PID.
- -e : Process name.
- -l : percentage of CPU allowed from 0 to 100.
- -P: absolute path name of the executable program file.