Skip to content

How to Enable/Disable CPUs (Limiting CPU count) in CentOS / RHEL?

Updated 1 min read

Updated: 28 September 2026 · Applies to: Ubuntu 24.04, Debian 12, AlmaLinux 9 and Rocky Linux 9

You can limit how many CPUs Linux uses, for example to test an application or for licensing. These steps work on Ubuntu 24.04, Debian 12, AlmaLinux 9 and Rocky Linux 9.

Note: On a Ucartz VPS the number of vCPUs comes from your plan. To get more or fewer, upgrade or change the plan in the client area instead.

Check the CPUs

nproc
lscpu | grep -E "^CPU\(s\)|On-line"

At runtime (until reboot)

echo 0 > /sys/devices/system/cpu/cpu3/online    # take CPU 3 offline
echo 1 > /sys/devices/system/cpu/cpu3/online    # bring it back

CPU 0 usually cannot be taken offline.

At boot (permanent)

nr_cpus=N limits the CPUs the kernel supports at all; maxcpus=N starts only N CPUs but lets you bring more online later.

grubby --update-kernel=ALL --args="nr_cpus=2"      # AlmaLinux / Rocky
# Ubuntu / Debian: add nr_cpus=2 to GRUB_CMDLINE_LINUX in /etc/default/grub, then:
update-grub

Reboot and check with nproc. Remove it with grubby --update-kernel=ALL --remove-args="nr_cpus".

Related services

KVM VPS hosting

NVMe SSD and full root access, with Free Basic Managed Support.

Unmanaged dedicated servers

full root access and free IPMI KVM, with Free Basic Managed Support.

Linux server management

hardening, patching, monitoring and automation for Ubuntu, Debian, RHEL and AlmaLinux.

Was this answer helpful?

Still stuck? Open a ticket