How to Limit CPU Usage of Heavy Processes in Linux Using cpulimit

Running intensive background jobs on a Linux workstation or home server—such as compiling software packages, batch transcoding 4K media with FFmpeg, compressing multi-gigabyte archives, or running complex machine learning scripts—often causes CPU consumption to hit 100% across all cores. When all CPU cycles are consumed by a single computational job, mouse cursor responsiveness stutters, audio playback crackles, desktop environments freeze, and laptop cooling fans spin at maximum velocity.

While the standard nice and renice commands allow you to adjust process scheduling priority, they do not actually prevent a background process from consuming 100% of an idle CPU. To enforce hard numerical percentage caps on resource usage, Linux users rely on cpulimit. Unlike complex kernel cgroups configurations, cpulimit works simply in user space by sending rapid POSIX pause (SIGSTOP) and resume (SIGCONT) signals to throttle execution. In this guide, we explore how to install cpulimit, throttle tasks by process ID (PID) or executable name, and automate background CPU management.

The Difference Between Process Priority (nice) and Resource Throttling (cpulimit)

Understanding how process priority contrasts with real-time execution throttling clarifies why cpulimit is the correct tool for CPU caps:

Throttling Mechanism Control Command Operating Behaviour Result on Idle System
Scheduling Priority nice / renice Alters CPU time allocation only when competing processes request cycles Process still consumes 100% CPU if no other high-priority task needs it
Hard Percentage Cap cpulimit Enforces strict percentage ceiling regardless of overall system activity Process stays strictly bounded (e.g. capped at 30% or 50% CPU)
Execution Timeout timeout Terminates commands entirely after a designated time duration Process is killed rather than regulated
Input/Output Throttling ionice Regulates hard disk read/write bandwidth priority Reduces storage contention without altering CPU speed

If you regularly run unmonitored scripts that might enter infinite loops or stall on remote network connections, you can also use the timeout command in Linux to run commands with time limits to automatically terminate hung processes.

Step-by-Step Tutorial: Installing cpulimit on Linux

The cpulimit utility is available in the standard repositories of virtually every Linux distribution:

  1. Open your terminal application.
  2. Install cpulimit using your native package manager:
    • Ubuntu / Debian / Linux Mint:
      sudo apt update && sudo apt install cpulimit
    • Fedora / RHEL:
      sudo dnf install cpulimit
    • Arch Linux / Manjaro:
      sudo pacman -S cpulimit
  3. Verify the command is ready by checking its version:
    cpulimit --help

Throttling an Active Process by Process ID (PID)

If an application is currently consuming excessive power and causing your laptop to overheat, locate its PID and cap its consumption:

  1. In one terminal window, run top or htop to identify the PID of the offending process (for example, PID 4821 consuming 98% CPU).
  2. To cap that process to 30% of a single CPU core, execute:
    sudo cpulimit -p 4821 -l 30
  3. The terminal will display: Process 4821 detected. cpulimit continuously pulses execution signals to keep total consumption at or below 30%.
  4. Press Ctrl + C to stop throttling and restore full CPU access whenever you choose.

Launching New Programs with Predefined CPU Limits

Rather than waiting for an intensive job to spike CPU usage before intervening, you can launch commands directly through cpulimit:

  • Launching a Video Transcoding Job at 50% CPU:
    cpulimit -l 50 -- ffmpeg -i input.mov -c:v libx264 output.mp4
  • Throttling by Executable Name in Background:
    To monitor and restrict any running instance of a specific binary (such as gzip) automatically in daemon mode, use the -e and -b flags:
    sudo cpulimit -e gzip -l 40 -b
  • When validating underlying files and filesystem blocks before heavy processing, you can also use the stat command in Linux to inspect file metadata and inodes to ensure targets are ready.

Understanding Multi-Core CPU Percentages

When calculating the limit value (-l) on modern multi-core processors, note how percentages scale:

  1. cpulimit measures 100% as the full capacity of a single logical CPU core.
  2. On a quad-core machine (4 cores), the total maximum CPU capacity is 400%. On an octa-core machine (8 cores / 16 threads), maximum capacity is 1600%.
  3. If you want a multi-threaded application (like Blender or a 7z compression archive) to utilize up to two full cores on a four-core computer, specify:
    cpulimit -e 7z -l 200

Frequently Asked Questions

Does cpulimit damage or corrupt files during intensive write operations?

No. cpulimit sends standard POSIX SIGSTOP and SIGCONT signals, cleanly freezing and resuming execution between cycles. The operating system handles buffers normally, ensuring data integrity is fully preserved.

Can regular non-root users run cpulimit?

Yes. Any user can run cpulimit against their own personal processes. However, limiting processes owned by root or other system accounts requires sudo privileges.

What is the difference between cpulimit and systemd resource controls?

cpulimit is a lightweight, on-demand command-line tool designed for instant desktop throttling without configuration files. Systemd slices and cgroups provide permanent, kernel-enforced service limits suited for production server daemons.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.