Thursday, February 25, 2010

How to Control the CPU Usage of a Process in Ubuntu / Debian Linux with cpulimit

 
CPULIMIT is a very good utility, this can be utilized for limiting the cpu usage of a process.  Limits are expressed in percentage, not in cpu time. This  does not act on the nice value or other scheduling priority , but on the real cpu usage. System administrators can effectively use this for avoiding there headace. The % limit from 0-100 for single processor 0-200 for dual processor.

How to install  cpulimit in Ubuntu / Debian

Open a Terminal and Type the following command to install cpulimit:

$ sudo apt-get install cpulimit

Usage

To limit CPU usage of the process called firefox to 40%, enter:

# cpulimit -e firefox -l 40

To limit CPU usage of the process to 40% by using its PID, enter:

# cpulimit -p 1313 -l 40

To find out PID of the process use any of the following:

# ps -u shibu  (list all process for the use shibu)
# ps aux | grep firefox

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

# cpulimit -P /opt/firefox/firebox -l 40

Where,

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