Linux nice Command: Setting Priority, Changing It with renice, and Measuring the CPU Share Under Contention

Affiliate disclosure v3.1
Affiliate disclosure v3.2 (mobile)
Test environmentRHEL familyAlmaLinux 9.8root · regular user accountChecked 2026-10-17

The Linux nice command sets a program's nice value (-20 to 19), which decides how much CPU it gives up to other processes when it runs. Measurements on an AlmaLinux 9 server, with two tasks pinned to a single CPU core and the nice value changed between runs, showed that the CPU was shared out only when the tasks competed for it, and the nice 19 task used just 1.4%.

Processes that are already running are changed with renice, and ionice handles giving way on the disk side. For all three commands, the output shown is exactly what they printed when run as root and as a regular user.

1️⃣ Linux nice Command: Value Range and the CPU Share Under Contention

The nice value is a number that sets how much a process gives way when CPU time is divided, and it can be set from -20 to 19. Programs normally run at 0; -20 is served first, and 19 gives way the most.

It is easy to assume a bigger number gets served first, but nice values work the other way round. The Linux scheduler assigns a weight to each nice value and divides CPU time in that ratio: nice 0 is 1024, 10 is 110 and 19 is 15.

Giving way only happens when tasks compete for the CPU. If there is an idle CPU, even a nice 19 task runs without waiting. It is like priority seats on a bus: when they are free anyone can sit, and people give up their seats only when the bus is crowded.

🧭 nice Values When the CPU Is Free vs. Contended
Explainer diagram
🖥️ CPU
⚖️ Task B
🖥️ An idle CPU is available, so each task gets its own core🖥️ Two tasks share one CPU core
Task Anice 0 · weight 1024
100%50.0%90.3%98.6%
Task Bnice 0 · weight 1024nice 10 · weight 110nice 19 · weight 15
100%50.0%9.7%1.4%
With CPU to spare there is no one to give way to, so task B uses the CPU fully whatever its nice value.
When they compete for the same core, two nice 0 tasks with equal weight split the CPU time in half.
nice 10 has a weight of 110, about one-ninth of nice 0 (1024), so CPU time is divided roughly 90.3 : 9.7.
nice 19 has a weight of 15; under contention, task B uses only about 1.4% of the CPU time.

The weight table is the [sched_prio_to_weight] array in the Linux kernel source [kernel/sched/core.c], and it is designed so that each one-step rise in the nice value cuts CPU time by about 10%.

2️⃣ Basic nice Usage: +10 When the Number Is Omitted, and Out-of-Range Values

Put a command after nice and that command runs with a changed nice value; type nice on its own and it prints the current shell's nice value.

nice
0

In the examples below, the bash that gets started prints its own nice value with [ps -o ni=]. Run without -n, 10 is added to the current value; with -n 5, 5 is added.

nice bash -c 'ps -o ni= -p $$'
 10
nice -n 5 bash -c 'ps -o ni= -p $$'
  5

Values outside the range are clamped to the limit without an error, so -n 50 runs at 19.

nice -n 50 bash -c 'ps -o ni= -p $$'
 19

Only root can move a process ahead with a negative value. A regular user gets the [cannot set niceness] warning, and the command still runs at nice 0.

# as a regular user
nice -n -5 bash -c 'ps -o ni= -p $$'
nice: cannot set niceness: Permission denied
  0
# as root
nice -n -5 bash -c 'ps -o ni= -p $$'
 -5

Child processes started by a command run under nice also run with the same nice value.

nice -n 7 bash -c 'sleep 1 & ps -o ni= -p $!'
  7

So if you run a script with nice, every command inside it gives way too.

3️⃣ renice: Changing the nice Value of a Running Process

nice only sets the value at launch, so for a process that is already running you use renice. First check the PID and the current value in top's NI column or with ps.

ps -o pid,ni,cmd -p 201643
    PID  NI CMD
 201643   5 sleep 600
renice -n 10 -p 201643
201643 (process ID) old priority 5, new priority 10

As the output shows, renice -n does not add to the current value but sets it to the value you give: the result is 10, not 5 + 10 = 15. It is not like pressing ▲ on an air-conditioner remote to go up one step, but like setting the target temperature to 24 degrees.

The official util-linux documentation also describes -n as an absolute value; adding is handled by the [--relative] option in newer versions. util-linux 2.37.4, the version tested, did not have this option.

A regular user can only raise the value of their own processes and cannot lower it again once it has been raised.

# as a regular user
renice -n 10 -p 201649
201649 (process ID) old priority 0, new priority 10
renice -n 5 -p 201649
renice: failed to set priority for 201649 (process ID): Permission denied

root can lower it as well; in the same test, it changed 10 straight to 3.

🔲 nice · renice Simulator

In the simulator below, logged in as a regular user, you can type nice and renice yourself and watch the nice value change.

nice Command Simulatornice 8.32 · renice 2.37.4
[root@server work]#
It runs only inside your browser and never touches a real process. The virtual server is logged in as a regular user: run something with a changed nice value, or change the value of backup.sh (PID 2481) with renice, then check it with ps -o pid,ni,cmd. Use the ↑↓ keys to bring back earlier commands.

4️⃣ Measuring the CPU Share Under Contention: nice 0 vs 0·10·19

Raising the nice value does not always slow the task down. Its share shrinks only when it competes with another task for the same CPU.

Two tasks were pinned to a single CPU core (taskset), and the script below, which counts up one number at a time for 5 seconds, was run in both at the same time. The higher the count, the more CPU time the task used.

#!/bin/bash
end=$((SECONDS+5)); n=0
while [ $SECONDS -lt $end ]; do n=$((n+1)); done
echo $n

The script increases n by 1 until 5 seconds have passed, then prints the final value.

📊5 seconds competing for one CPU coreCount reached in 5 seconds
First task nice 0Second task
nice 0 vs nice 0
Two tasks with the same weight.
0250K500K750K1M
nice 0497,59648.8%
nice 0522,04051.2%
nice 0 vs nice 10
Only the second task runs at nice 10.
0250K500K750K1M
nice 0979,97190.1%
nice 10107,6719.9%
nice 0 vs nice 19
Only the second task runs at nice 19.
0250K500K750K1M
nice 0909,89598.6%
nice 1913,0101.4%
Figures from an AlmaLinux 9 server on October 17, 2026, with the two tasks pinned to one CPU core and run simultaneously for 5 seconds each.

Two nice 0 tasks split it in half, while nice 10 used about 10% and nice 19 just 1.4%. This matches the ratios calculated from the kernel weights (1024 : 110 gives 90.3 : 9.7, and 1024 : 15 gives 98.6 : 1.4).

Run alone on the same core, the nice 19 task counted roughly 650,000 to 1,140,000 times in 5 seconds. With nobody to give way to, even nice 19 uses the CPU fully; the server load (load average) was 3 to 5 during the test.

5️⃣ ionice: Giving Way on Disk I/O and Checking the Scheduler

nice only decides the CPU share, so for tasks that read and write the disk for a long time, such as backups, use ionice to give way on disk order as well. Run with -c3 (idle), a task is served only when no other program is using the disk.

ionice -c3 bash -c 'ionice -p $$'
idle
ionice -p $$
none: prio 0

A process with no class set is shown as [none]; according to the kernel documentation, it is treated as best-effort, with its priority calculated from the CPU nice value.

ionice classes only take effect when the disk scheduler supports them, and the kernel documentation lists bfq and mq-deadline as supporting schedulers. The one shown in brackets is the scheduler currently in use.

cat /sys/block/nvme0n1/queue/scheduler
[none] mq-deadline kyber bfq

The NVMe disk on the test server uses [none], so according to the official documentation ionice may have no effect there; the effect was not measured separately. Check the disk name with lsblk.

6️⃣ Where to Use nice: Backups · Cron · wp-cli

Add nice to jobs that take a long time but are not urgent. Backup compression uses both CPU and disk, so set nice and ionice together.

nice -n 19 ionice -c3 tar czf backup.tgz /home/example

If a job that is already running slows the server down, find its PID in top and raise its value with renice; for cron jobs that run every day, put nice in front of the command.

0 3 * * * nice -n 10 /usr/local/bin/backup.sh

On a WordPress server, if you run big wp-cli jobs such as search-replace or image regeneration with nice -n 10, php-fpm, which handles visitor requests, gets the CPU first when it is busy.

nice -n 10 wp media regenerate --yes

On the other hand, do not raise the nice value of php-fpm or the web server itself. If the processes that answer visitors give way, pages respond more slowly when the CPU is busy.

🔢 FAQ & Recommended Content

For normal processes, PR in top is shown as 20 plus the nice value. A process started with nice 5 showed PR 25 and NI 5, while the PRI column in ps uses a different calculation and showed the same process as 14.

nice adds the given value to the current nice value. [nice -n 5 nice -n 3 nice] prints 8, which is different from renice -n, which sets the value to the one you give.

Add [Nice=] to the [Service] section of the service's unit file, and that sets the nice value of the processes the service runs. According to the official systemd.exec documentation, it can be set from -20 to 19.

🧭 Processes and job scheduling: recommended content 11 posts · 4 references
🗂️ Processes and job scheduling
📄 ps command 📄 top command 📄 Linux nice command 📄 kill command 📄 killall command 📄 Background & foreground 📄 uptime command
📄 crontab setup
📋 WP CLI: Installation and Setup 📄 WP-Cron(wp-cron.php) 📄 Find synced patterns: WP-CLI
📡 GNU Coreutils nice invocation 📡 renice(1) Linux manual page 📡 Block io priorities (kernel docs) 📡 sched_prio_to_weight (kernel source)

ℹ️ Affiliate Disclosure
This site's content contains affiliate links. When a visitor buys a product or service through one of them, the site receives a commission from the seller. The amount the buyer pays(it goes down during event discounts ↓)does not go up. Posted prices, discounts, and stock reflect the time of writing and may differ, so confirm with the seller before buying. Products are chosen and reviewed by our own standards, and commissions do not affect the order or content of reviews.

Leave a Reply

Your email address will not be published. Required fields are marked *

Prove your humanity: 7   +   8   =