nice Command Guide for Starting Programs at Lower Priority
nice runs a command with a chosen CPU priority — a higher “nice” value means the program yields more to everyone else.
What is nice, and Why Use It?
The nice command starts a program with a niceness value set: a number from −20 (greedy, takes priority) to 19 (polite, yields to others). The scheduler uses niceness to decide how CPU time is shared — a niced-down backup job will not starve the editor you are typing in. nice is how you set that priority before the program starts; renice changes it afterward.
Why Learn nice?
- Be a good citizen: long batch jobs (compiles, backups, transcodes) should not hog CPU from interactive work.
- Protect interactive work: running something important?
nice -n -10(needs privileges) or lower others withrenice. - No config needed: priority is set per-invocation, on the command line.
- Pairs with
renice:nicefor launch-time,renicefor mid-flight — one concept, two commands.
niceis the politeness knob of Linux: the higher the number, the more the program says “excuse me” to the scheduler.
1. Basic Usage: Run Niced-Down
# Start a backup at niceness 10 (very polite)
nice -n 10 ./backup.sh
# Without -n, nice uses its default increment of 10:
nice ./job.sh # same as nice -n 10 ./job.sh
nice cmdwithout-nstarts the command at niceness 10 (the default increment).nice -n 19 cmdis the most polite setting — the program yields to nearly everything.
See the niceness of a running process with ps:
ps -o pid,ni,cmd -p $(pgrep -f job.sh)
- The
NIcolumn shows the niceness value;0is the neutral default.
2. The Niceness Scale
nice -n -5 ./important.sh # greedy — needs privileges (see below)
nice -n 0 ./normal.sh # neutral
nice -n 19 ./polite.sh # yields to everyone
| Niceness | Meaning |
|---|---|
| −20 | Highest priority (only root may set) |
| 0 | Default |
| 19 | Lowest priority |
- Regular users may only increase niceness (0 → 19); lowering it (negative) requires root.
- Niceness affects CPU scheduling only — it does not throttle disk or network use.
3. Running with sudo for Higher Priority
# Run at niceness -5 (needs root)
sudo nice -n -5 ./critical-job.sh
# Or use renice on an already-running process instead
- The rule: raising priority (negative niceness) requires root; lowering it (positive) does not.
- Prefer
renicefor adjusting processes that are already running.
4. Combining with Pipes and Scripts
# Niced-down pipeline
nice -n 15 tar -czf backup.tar.gz /home | \
nice -n 15 gzip > /mnt/backup/backup.tar.gz
# In a script: run everything politely
for f in *.raw; do
nice -n 10 convert "$f" "${f%.raw}.png"
done
- Each
niceapplies to the command it starts; pipelines need it per stage or wrapped in a subshell.
5. nice vs. renice
| Situation | Command |
|---|---|
| Starting a new program with priority set | nice |
| Changing priority of a running program | renice |
nice -n 10 ./long-job.sh & # start polite
renice -n 5 -p $(pgrep long-job) # later, make it a bit greedier
niceis launch-time;reniceis mid-flight. Both move the sameNIvalue.
Common Pitfalls
- Negative niceness silently fails without root:
nice -n -5 cmdas a normal user runs at niceness 10 anyway (or errors) — check withps. - Niceness is not a hard cap: a niced program still gets CPU when nothing else wants it; it only loses contests.
- It does not affect I/O or network: for disk-throttled copies use
ionice; niceness is CPU-only. - Children inherit niceness: a niced shell passes its politeness to everything it spawns.
nicethe command vs. “nice” the value: the command sets the value at launch; the value is whatreniceedits later.
Related Pages
| Page | Relationship |
|---|---|
renice | Changes priority of running processes — the mid-flight twin. |
ps | ps -o ni shows the niceness of any process. |
top | Live view includes the ni column. |
nohup | Combine with nice for polite, logout-proof jobs. |
jobs | Track the niced job you backgrounded. |
nice Cheatsheet
| Command | What It Does |
|---|---|
nice cmd | Start cmd at niceness 10. |
nice -n 19 cmd | Start at the lowest priority. |
nice -n 5 cmd | Start slightly more polite than default. |
sudo nice -n -5 cmd | Start at high priority (root only). |
ps -o ni,cmd | See niceness values. |
renice -n 5 -p pid | Change priority of a running process. |