Operating System CentOS

How to Install and Use cpulimit on AlmaLinux 9, Ubuntu 26.04 and Debian 13

Install cpulimit from EPEL or the distribution repositories, limit a running process or a new command to a CPU percentage, and compare it with systemd's CPUQuota.

cpulimit caps the CPU usage of a process at a percentage you choose. This guide installs it on AlmaLinux 9 / Rocky Linux 9 and on Ubuntu 26.04 LTS and Debian 13, shows how to limit a running process and a new command, and covers the systemd alternative that is usually the better choice for services. CentOS 7 reached end of life in June 2024; AlmaLinux 9 and Rocky Linux 9 are its direct replacements and use the same dnf commands.

How cpulimit works

cpulimit does not change scheduling priority. It watches the target and repeatedly pauses it with SIGSTOP and resumes it with SIGCONT, so that its average CPU usage stays under the limit. That has two consequences: the process runs in short bursts rather than slowly, and programs that react to being stopped, such as interactive shells with job control, can misbehave. Batch jobs, encoders, compilers, backup scripts and most daemons work fine.

The limit is a percentage of one core. On a four-core server the valid range is 0 to 400, and -l 50 means half of one core, not half of the machine.

Two programs with the same name

Distributions ship two different implementations under the package name cpulimit, and their options are not identical:

SystemPackage sourceVersionUpstream
AlmaLinux 9 / Rocky Linux 9EPEL 90.2opsengine/cpulimit
Ubuntu 26.04 LTSuniverse3.2LimitCPU
Ubuntu 24.04 LTSuniverse3.0LimitCPU
Debian 13main3.1LimitCPU
Debian 12main2.8LimitCPU

The basic options -l, -p, -e and -z work in both. LimitCPU adds background mode, a kill mode and several others; the EPEL build has -i to include child processes instead.

Install cpulimit

On AlmaLinux 9 or Rocky Linux 9, enable EPEL and install the package:

sudo dnf install epel-release
sudo dnf install cpulimit

On Ubuntu 26.04, Ubuntu 24.04, Debian 13 or Debian 12:

sudo apt update
sudo apt install cpulimit

Check which implementation you have by reading its help text:

cpulimit --help

Limit a running process

Find the process ID with top, ps or pgrep:

pgrep -a ffmpeg

Then cap that PID. This example holds process 12345 to 30% of one core:

sudo cpulimit -p 12345 -l 30

cpulimit stays in the foreground while it controls the process and exits when the target ends. Press Ctrl+C to remove the limit; the target continues at full speed. You need sudo only when the target belongs to another user.

You can also select the target by executable name. cpulimit takes the first matching process it finds, so use the PID when several instances are running:

sudo cpulimit -e ffmpeg -l 30

When you select by name, cpulimit keeps waiting for a matching process to appear and reattaches when it restarts. Add -z to make it exit as soon as there is no target.

Start a command with a limit

Both implementations can launch a program and throttle it from the first second. On Ubuntu and Debian (LimitCPU), separate the command with --:

cpulimit -l 50 -- gzip -9 /var/backups/site.tar

On AlmaLinux and Rocky Linux (EPEL build), put the command after the options:

cpulimit -l 50 gzip -9 /var/backups/site.tar

Run cpulimit in the background

LimitCPU on Ubuntu and Debian has a background switch that frees the terminal:

sudo cpulimit -p 12345 -l 30 -b

The EPEL build has no such option. Send it to the background with the shell instead:

sudo sh -c 'nohup cpulimit -p 12345 -l 30 >/dev/null 2>&1 &'

To lift the limit later, stop the cpulimit process itself:

sudo pkill cpulimit

Child processes

A limit applies to the process you name, not automatically to processes it starts. That matters for scripts and for servers that fork workers. The EPEL build includes children with -i:

sudo cpulimit -p 12345 -l 50 -i

LimitCPU offers -m (--monitor-forks) for the same purpose, but its manual page warns that this is usually a bad idea, particularly with shell scripts. For anything with many children, use a control group as described next.

The systemd alternative: CPUQuota

For services, and for any process tree, the kernel's cgroup CPU controller is more accurate than stop/continue signals and covers all children automatically. systemd exposes it as CPUQuota, again as a percentage of one core. To cap an existing service at half a core, persistently:

sudo systemctl set-property nginx.service CPUQuota=50%

To run a one-off command under a quota:

sudo systemd-run --scope -p CPUQuota=50% gzip -9 /var/backups/site.tar

Remove a quota from a service by setting it to an empty value:

sudo systemctl set-property nginx.service CPUQuota=

Keep cpulimit for quick, ad-hoc throttling of a process that is already running and that you do not want to restart.

Verify the limit

Watch the target while cpulimit is active. The %CPU column should hover around the value you set, and the state column switches between R and T (stopped):

top -p 12345

Frequently asked questions

Is cpulimit the same as nice?

No. nice lowers priority, so the process still uses 100% of a core when nothing else wants it. cpulimit and CPUQuota enforce a ceiling even on an idle machine, which is what you need to stay under a provider's fair-use threshold or to keep temperatures and bills down.

Why does my limited process show as stopped?

That is the mechanism at work: the process is paused for part of every time slice. If it stays stopped after cpulimit was killed abruptly, resume it with kill -CONT 12345.

Can I get the newer LimitCPU on AlmaLinux 9?

EPEL only carries the 0.2 build. LimitCPU publishes source tarballs on its SourceForge project page; it builds with gcc and make and installs with sudo make install. In most cases CPUQuota is the simpler route on RHEL-family systems.

Does the limit survive a reboot?

No. cpulimit only affects processes while it is running. For a permanent cap on a service, use systemctl set-property, which writes a drop-in file that systemd applies on every start.

Share story:

Continue reading other guides on How VPS.