Limit the CPU of a process without touching its priority.
cpulimit alternates SIGSTOP and SIGCONT within short chunks and corrects the duty cycle from the CPU time the target actually used, so the limit follows system load. It is made for batch jobs that must not eat the machine.
Version 1.0.3 · GPL-2.0-or-later · release notes
# an existing process: half a CPU
cpulimit -l 50 -p 1234
# by name, with its children
cpulimit -l 25 -i -e ffmpeg
# start a command and limit it; the exit status is the command's
cpulimit -l 80 -- make -j8
# background daemon with syslog and a pid file
cpulimit -d -s -P /run/cpulimit.pid -l 30 -e backupWhy this one
A fork of Angelo Marletta's cpulimit, kept compatible with it: the options -p -e -l -c -i -m -v -z, the exit statuses and the log lines are unchanged, so existing scripts keep working.
Follows the load
The next run slice is computed from the CPU time the target really used in the last chunk, not from a fixed duty cycle. How it works
Never strands a target
Every exit path sends SIGCONT first. The one thing no user-space program can survive is SIGKILL of itself; the FAQ says what to do.
Safe identity
A process is its pid and start time, so a recycled pid is never limited by mistake, and two limiters cannot fight over one target.
Operable
Daemon mode with syslog and a pid file, strict option parsing, exit statuses documented in the man page, static musl builds.
Tested in the open
Unit, integration, fuzz, sanitizer, mutation and model-checking harnesses, with their limits stated. Verification
Many systems
Linux, macOS, FreeBSD, OpenBSD, NetBSD and Solaris/illumos have an iterator; what is actually tested where is spelled out.
Get started
git clone https://github.com/denji/cpulimit.git
cd cpulimit
make && sudo make install
cpulimit -l 30 -- gzip -9 big.tarGNU make and a C compiler are all it takes (gmake on the BSDs and illumos). Install covers static builds, packaging variables and the platform notes; Usage has every option, the exit statuses and worked examples.