CPU Usage Limiter for Linux

cpulimit 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.

How it works

The work of cpulimit is done all in userspace, so it doesn’t interfere with the Linux scheduler. Basically, the target process, which you can specify by pid, name, or command line, is continuosly paused and resumed by sending it SIGSTOP and SIGCONT signals. Signals are sent by cpulimit in appropriate moments, based on the limit specified by user and the process statistics read from /proc.

System Requirements

cpulimit should run on every Linux 2.2 or greater. It has been reported by several users that cpulimit works fine even on SMP hardware, but consider that if you have more than one cpu there is a little difference in the meaning of cpu usage.

Instructions

Download:

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

OR get the latest source code from Subversion repository with this command:

svn checkout https://cpulimit.svn.sourceforge.net/svnroot/cpulimit/trunk cpulimit

Then extract the source and compile with make:

tar zxf cpulimit-xxx.tar.gz
cd cpulimit-xxx
make

Executable file name is cpulimit. You may want to copy it in /usr/bin.

Examples of use

Limit the process ‘bigloop’ by executable name to 40% CPU:

cpulimit –exe bigloop –limit 40
cpulimit –exe /usr/local/bin/bigloop –limit 40

Limit a process by PID to 55% CPU:

cpulimit –pid 2960 –limit 55

Launch a process by command line and limit it to 40% (in development version only!):

cpulimit –limit 40 /etc/rc.d/rc.boinc start

Advertisements