How To Limit CPU Usage Per Process In Linux

by lifeLinux on September 13, 2011

To limit CPU usage per process in Linux, you can use cpulimit. It is a simple program which attempts to limit the cpu usage of a process (expressed in percentage, not in cpu time). This is useful to control batch jobs, when you don’t want them to eat too much cpu. It 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.

Install cpulimit

Type the following commands to install latest version of cpulimit

# wget
# tar zxvf cpulimit-1.1.tar.gz
# cd cpulimit-1.1
# yum install make -y
# make
# cp cpulimit /usr/local/sbin/

If you are using Ubuntu / Debian, you can also use apt-get to install cpulimit, type the following command

# sudo apt-get install cpulimit

How to use cpulimit

Usage: cpulimit TARGET [OPTIONS...]
   TARGET must be exactly one of these:
      -p, --pid=N        pid of the process
      -e, --exe=FILE     name of the executable program file
      -P, --path=PATH    absolute path name of the executable program file
      -l, --limit=N      percentage of cpu allowed from 0 to 100 (mandatory)
      -v, --verbose      show control statistics
      -z, --lazy         exit if there is no suitable target process, or if it dies
      -h, --help         display this help and exit

Example, I want to limit CPU usage of process called httpd to 20%, i will enter

# cpulimit -e httpd -l 20

To limit CPU usage of process had PID is 1673 to 20%, enter

# cpulimit -p 1673 -l 20

You can also use name of the executable program file, enter

# cpulimit -P /usr/local/zend/apache2/bin/httpd -l 20

{ 3 comments… read them below or add one }

wobuelweb March 19, 2012 at 3:45 pm

hello sir

how do i can limit cpu process by username in cpanel

it is possible ?
thanks great article


lifeLinux March 21, 2012 at 2:54 pm

In Cpanel I highly recommend using CloudLinux


Phill January 28, 2013 at 11:11 am

I would also love to limit by user as well, I am on a WHM/CPanel VPS everything is great until a particular website runs a cron once a week and takes the CPU load up to 35 CPU’s, since I only have 4 CPU’s available for everything is is a problem


Previous post:

Next post: