Skip to content

nice Command Cheat Sheet

The nice command is used to start a program with a modified scheduling priority.

Concept: "Niceness" ranges from -20 (Highest Priority, least nice) to +19 (Lowest Priority, most nice to others). Default is 0.


Synopsis

nice [OPTION] [COMMAND [ARG]...]

Basic Usage

Start with Lower Priority (Positiv Nice)

Make a backup command "nicer" so it doesn't slow down the web server.

nice -n 10 tar -czf backup.tar.gz /var/www
Or simply (default increment is 10):
nice tar -czf backup.tar.gz /var/www

Start with Higher Priority (Negative Nice)

Requires sudo. Only root can be "selfish" (less nice).

sudo nice -n -10 ./critical_process

Verifying Niceness

Check Priority (ps)

The NI column shows the nice value.

ps -fl -C tar
# OR
top
(Look for the NI column in top).


Renice (Changing Running Process)

If a process is already running, use renice.

# Slow down process 1234
renice -n 5 -p 1234

# Speed up process 1234 (Root only)
sudo renice -n -5 -p 1234

Renice by User

Change priority of ALL processes owned by a user.

sudo renice -n 10 -u alice

Notes

  • CPU Scheduler: nice only affects CPU scheduling. It does not prioritize I/O (see ionice for that).
  • Inheritance: Child processes inherit the nice value of their parent.
  • -20 vs 19:
    • -20: The process tries to grab every CPU cycle it can.
    • 19: The process runs only when the CPU is idle.