sysadmin · difficulty ◆◆
nice & renice — run the heavy job without starving the box
Niceness is a weight, not a switch — 19 means 'after everyone else', and the kernel does the rest.
Two identical loops, one core, one command line apart: 98.5 % CPU for one, 1.5 % for the other. The difference is a number you set before you press Enter.
fully AI-generatedThis text is fully AI-generated and was published without human editorial review.$ niceThe number, and which way it points
Niceness runs from **-20 to 19**, default **0**, and it points backwards from intuition: the *lower* the number, the *more* CPU the process gets. -20 is a process that elbows its way in; 19 is one that hangs back politely. That inverted scale is why `nice -n 19` makes a job *slower* and why the flag name confuses people for a decade.
`nice` sets the value before the program is executed, and every child it forks inherits it. `renice` changes the value of a process that is already running. Both write the same per-process field that `ps` prints as `NI` and `top` prints in its own `NI` column. Without root, and without a `limits.conf` entry or `CAP_SYS_NICE`, you can only ever move in one direction: upward, towards 19, towards yielding.
It is a weight, not a percentage
The old BSD scheduler handed out time proportional to `20 - priority`. Linux's CFS replaced that with weights from a lookup table: a nice 0 task weighs 1024, a nice 19 task weighs 15. When they compete for the same core, the split is 1024 : 15 — 98.5 % against 1.5 %. I measured exactly that on this 12-core box by pinning two identical Python loops to CPU 3, one of them at nice 19.
Which tells you the other half of the story: on an **idle** box, nice buys nothing at all. That same loop at nice 19 still showed 100 % CPU in `ps`, because nobody was asking for the core it was sitting on. Niceness only becomes real under contention, and its effect scales with how badly the machine is oversubscribed.
Where nice stops helping
Nice is a CPU knob. A `nice -n 19 rsync` is still perfectly capable of filling the disk queue and making every login on the box feel broken, because the bottleneck was never the scheduler — it was the device. For that you want `ionice -c 3` (idle I/O class) or `ionice -c 2 -n 7` (best-effort, lowest priority).
For services, stop reaching for `nice` altogether: systemd has `CPUWeight=`, `IOWeight=` and `Nice=` in the unit file, plus `CPUQuota=` for a hard cap. `nice` is the right tool for the ad-hoc thing you are about to type, not for something that should be configured once.
Example
$ nice -n 19 tar -czf /tmp/usrshare.tgz /usr/share &
ps -o pid,ni,cmd -C tar PID NI CMD
2718005 19 tar -czf /tmp/usrshare.tgz /usr/shareReal output. `-C tar` selects by executable name, which beats `| grep tar` — grep matches its own command line and the shell that spawned it. NI 19 in the snapshot is the proof it started demoted, and every process tar forks for compression inherits it.
$ taskset -c 3 python3 -c 'while True: pass' &
taskset -c 3 nice -n 19 python3 -c 'while True: pass' &
sleep 6; ps -o pid,ni,pcpu,cmd -C python3 PID NI %CPU CMD
2718273 0 98.5 python3 -c while True: pass
2718274 19 1.5 python3 -c while True: passThe measurement behind the claim: two identical loops pinned to one core with taskset, so they actually fight. 98.5 / 1.5 is the 1024 : 15 weight ratio of the CFS table to two decimal places. If you only remember one thing about nice, remember that this is what the number buys.
$ ps -o pid,ni,pri,pcpu,cmd -p 2719939
renice -n 19 -p 2719939
ps -o pid,ni,pcpu,cmd -p 2719939 PID NI PRI %CPU CMD
2719939 0 19 100 python3 -c while True: pass
2719939 (process ID) old priority 0, new priority 19
PID NI %CPU CMD
2719939 19 100 python3 -c while True: passReal transcript. 100 % before, 100 % after — this box had eleven cores going spare, so the demotion changed the weight and the scheduler had nothing to weigh it against. `old priority 0, new priority 19` is renice's full success message, on stdout, exit 0.
$ renice -n 10 -p 2719939renice: failed to set priority for 2719939 (process ID): Permission deniedNot a bug. Going 19 → 10 is *raising* priority, and an unprivileged user can only ever increase niceness. Exit status 1, NI stays at 19. The way back is root, or a `@admins - nice -10` line in /etc/security/limits.conf and a fresh login.
$ nice -n 10 sh -c 'nice'
nice -n 20 sh -c 'nice'
nice -n abc true10
19
nice: invalid adjustment ‘abc’Bare `nice` with no command prints the niceness it inherited and exits 0 — the cheapest way to check what a cron line or a supervisor handed you. `-n 20` is silently clamped to 19 with no warning at all, and garbage exits 125 before anything runs. Also worth knowing: `nice -n -5 cmd` as a user prints `nice: cannot set niceness: Permission denied` and then runs the command anyway, at the old value.
Common flags
- -n 19
- Adjustment added to the inherited niceness. Range -20..19; out-of-range values clamp silently (20 becomes 19).
- -n -10
- Negative values need root or CAP_SYS_NICE. Without it GNU nice warns, keeps the inherited value, and runs the command regardless.
- -10
- The 1973 spelling, still accepted by GNU coreutils. `nice -10 cmd` is identical to `nice -n 10 cmd`.
- --adjustment=19
- Long form of -n. Useful in scripts where a leading-dash argument would otherwise be read as an option.
- renice -n 19 -p PID
- Change a running process. Prints old and new priority; exit 1 on refusal.
- renice -u user
- Every process belonging to a user. `-g` does a process group instead — handy for a job spread across workers.
- ionice -c 3
- Not nice, but the companion you actually need for disk-bound jobs: idle I/O class, only touched when the device is free.
History
November 1973: a scheduling knob named after politeness
nice landed at Bell Labs in November 1973 and has barely changed shape since: one number, one command to run. The value is called *niceness* because a process asking for less CPU is being nice to its neighbours — the metaphor is the whole documentation, and it survived into every Unix manual written after it.
So did the privilege rule. Only the superuser could lower niceness in 1973, and on Linux today that is still enforced by CAP_SYS_NICE, with `limits.conf` standing in for the operator who used to decide case by case.
Same flag, different arithmetic underneath
The interface outlived the scheduler behind it. BSD-era Unix handed out time proportionally to `20 - priority`, so nice 15 got a clean quarter of the CPU against nice 0. Linux's CFS threw that away for weighted fair queueing: niceness indexes a weight table, and shares come out as weight ratios — 1024 against 15 at the extremes, not 20 against 5.
On modern Ubuntu the two commands even live in different packages — `nice` in coreutils, `renice` in bsdutils — which is a small fossil of that history. The arithmetic changed twice; the command line did not change at all.
Fun facts
Pros & cons
pros
- + One number set before exec, inherited by every child the job forks — no daemon, no config file, no cgroup to create.
- + Works identically on a 1973 PDP-11 and in a 2026 container, because the kernel interface never moved.
- + renice lets you demote a runaway process you did not plan for, without killing it and losing its work.
cons
- − CPU only. It says nothing about disk, network or memory pressure, which are usually the real bottleneck.
- − Effect is invisible without contention: 100 % CPU before and after on an idle box, which makes it feel useless.
- − Unprivileged users can only move one way, so a wrong renice cannot be undone without root or a limits.conf change.
Takeaways
- 1Prefix anything batch-shaped with `nice -n 19` — a backup, a reindex, a log rotation — and the children inherit it for free.
- 2Confirm it actually took: `ps -o ni= -p PID` must print 19. A nice that failed on a permission error still ran your command.
- 3Judge nice only under contention; on an idle machine a demoted process still eats a full core.
- 4Without root you can only ever increase niceness, so decide the demotion up front instead of planning to undo it.
- 5Disk-bound jobs need `ionice -c 3`, not nice, and services belong in a systemd unit with `CPUWeight=` / `IOWeight=`.
Related commands
archive entry — written and published by a scheduled job, never editorially reviewed. Kept for reference: out of the site’s search index, and no ads run here. the reviewed library →
