cpulimit
Limit CPU usage of a process
TLDR
Limit an existing process with PID 1234 to only use 25% of the CPU
Limit an existing program by its executable name
Launch a given program and limit it to only use 50% of the CPU
Launch a program, limit its CPU usage to 50% and run cpulimit in the background
Kill its process if the program's CPU usage goes over 50%
Throttle both it and its child processes so that none go about 25% CPU
SYNOPSIS
cpulimit [-h] [-v] [-z] [-r] [-p PID] [-l LIMIT] [-e EXE] [-a] [-k] [-u UID] [COMMAND [ARGS]]
PARAMETERS
-h, --help
display help and exit
-v, --verbose
output verbose information
-z, --zero
exit if limit is 0
-r, --recursive
limit also child processes
-p PID, --pid PID
specify PID to limit (instead of command)
-l LIMIT, --limit LIMIT
limit CPU to LIMIT% (1-100, default 50)
-e EXE, --exe EXE
specify executable name to limit (all matching)
-a, --average
use average CPU over interval (not instantaneous)
-k, --keep-running
keep process running even if throttling misses deadlines
-u UID, --uid UID
limit processes owned by UID
DESCRIPTION
cpulimit is a simple Linux utility designed to throttle the CPU consumption of a process or program to a specified percentage. It prevents resource hogging by CPU-intensive tasks, ensuring system responsiveness.
The tool works by interleaving execution with pauses: it monitors the process's CPU usage and sends SIGSTOP to suspend it when exceeding the limit, resuming with SIGCONT. This signal-based approach is lightweight but approximates the limit rather than enforcing it precisely, especially on multi-core systems where it throttles the entire process (summing threads' usage).
Key use cases include running benchmarks without starving interactive apps, limiting batch jobs, or testing software under constrained resources. It complements nice (priority adjustment) by directly capping usage. Specify limits via percentage (1-100%), target by PID, executable name, or launch new commands. Supports recursive child limiting and verbose logging.
Not ideal for real-time or highly precise needs; modern alternatives like cgroups offer finer control.
CAVEATS
Signal-based throttling is imprecise on multi-core CPUs; treats process threads as one unit. Does not limit I/O or memory. Ineffective against processes ignoring SIGSTOP/CONT. No support for cgroups or namespaces.
EXAMPLES
cpulimit -l 30 -p 1234
Limit PID 1234 to 30% CPU.
cpulimit -l 50 stress --cpu 8
Launch stress using 50% total CPU.
cpulimit -l 20 -e firefox -r -v
Limit all firefox instances recursively with verbose output.
HISTORY
Developed by Amos Benari around 2006 as open-source tool. Maintained sporadically; version 0.2 (2011) added features like recursion. Widely used in scripts for resource control pre-cgroups era.


