Tuesday, September 21, 2010

Limit CPU Usage Per Process in Linux

This practical is tested successfully on Fedora 11 i386 & CentOS 5.4 Only.

Download "cpulimit" setup file first.

wget '
http://downloads.sourceforge.net/cpulimit/cpulimit-1.1.tar.gz'

Extract it & go inside the directory.
tar -zxvf cpulimit-1.1.tar.gz

cd cpulimit-1.1

make

cp cpulimit /usr/local/sbin/
rm -rf cpulimit*

Command to run cpulimit.


To limit CPU usage of the process called firefox to 30%, enter:
# cpulimit -e firefox -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 firefox


# pgrep -u nnv php-cgi


# pgrep lighttpd


You can also use absolute path name of the executable, enter:

# cpulimit -P /opt/firefox/firebox -l 30
Where,

* -p : Process PID.
* -e : Process name.
* -l : percentage of CPU allowed from 0 to 100.
* -P: absolute path name of the executable program file.

Thanks,
Nishith N.Vyas.
Call : +91 9879597301

No comments:

Post a Comment