opscape

Processes and jobs

nice

Run a command with a lower (or, as root, higher) CPU scheduling priority, or print the current niceness.

nice [-n ADJUSTMENT] [COMMAND [ARG...]]

8 of 8 examples run in Debian 13.7 on 2026-10-31 · coreutils 9.7-3 · manual: nice(1)

Every process has a niceness from -20 to 19. The higher the number, the "nicer" the process is to others: when the CPU is contended, the scheduler gives it a smaller share. Niceness only matters when something else wants the CPU; on an idle machine a niced job runs at full speed. nice -n 10 make -j8 is the classic use: a big build or compression job that should not make the rest of the machine sluggish.

nice adds its adjustment to the current niceness (default +10) and starts the command with the result, clamped to 19. Children inherit the value, so niceness set on a script applies to everything it runs. Ordinary users can only make things nicer; lowering the number (raising priority) needs root, or more precisely the CAP_SYS_NICE capability. To change a process that is already running, use renice.

Niceness governs CPU only. For a job that hammers the disk, ionice -c3 (idle I/O class) is the companion tool; the two are often combined: nice -n 19 ionice -c3 tar czf .... In ps and top, niceness is the NI column.

Examples

Print the current niceness

nice
explain
output
0

With no command, nice prints the niceness it inherited. Shells and services normally start at 0.

Run a command at lower priority

nice nice
explain
output
10

The outer nice runs the inner one with the default adjustment of +10, and the inner one prints what it got. Any command works in place of the inner nice.

Choose the adjustment

nice -n 5 nice
nice -n 19 nice
nice -n 50 nice
output
5
19
19

-n N adds N. 19 is the lowest priority there is; larger adjustments are silently clamped to it, as the third line shows.

Adjustments add up

nice -n 5 nice -n 3 nice
explain
output
8

The first nice starts at 0 and gives 5; the second adds 3 to that. Niceness is relative to whatever the parent had.

See niceness in the process list

nice -n 10 sleep 300 &
sleep 300 &
ps -o pid,ni,pri,args -C sleep
output
    PID  NI PRI COMMAND
   1615  10   9 sleep 300
   1616   0  19 sleep 300

The NI column shows niceness. PRI is the kernel's resulting priority as procps reports it, where a higher niceness gives a lower number; compare NI, which is what you set.

Children inherit the niceness

nice -n 7 bash -c 'sleep 300 & ps -o ni=,args= -p $!'
explain
output
  7 sleep 300

The shell started under nice has niceness 7, and so does the sleep it starts. Niceness a script starts with applies to everything it runs.

Raising priority needs privileges

nice -n -5 nice
echo "exit status: $?"
output
nice: cannot set niceness: Permission denied
0
exit status: 0

An unprivileged user cannot lower niceness. GNU nice warns cannot set niceness: Permission denied but still runs the command at the unchanged value (0) and returns its status. As root, sudo nice -n -5 cmd works.

Run a heavy job in the background without slowing the machine

nice -n 19 gzip -k -9 access.log &
wait
ls -l access.log*
output
-rw-rw-r-- 1 dev dev 2309 Oct 24 21:55 access.log
-rw-rw-r-- 1 dev dev  591 Oct 24 21:55 access.log.gz

The usual pattern for compression, backups and builds: nice it fully and background it. On a busy machine the job yields to interactive work; on an idle one it finishes just as fast.

Common pitfalls

  • Writing nice -10 cmd and expecting -10. In that old syntax -10 means an adjustment of +10; a negative value would be --10. Use -n and the meaning is unambiguous.

  • Expecting nice to help with disk or memory contention. It only affects CPU scheduling; use ionice for disk I/O.

  • Niceness is not a hard limit. A niced job on an idle machine still uses 100% of a core. To cap CPU use, use cgroups (systemd's CPUQuota=) or cpulimit.

  • Assuming a failed negative adjustment stops the command. GNU nice only warns and runs it anyway at the old niceness.

GNU vs BSD and macOS

The examples above ran the GNU/Linux version. These are the differences that matter on macOS and the BSDs (written from their documentation, not run here).

  • nice -n N is POSIX and works the same on macOS and the BSDs. The shell may have its own nice builtin (csh and tcsh do) with slightly different syntax; command nice or /usr/bin/nice gets the standalone program.

  • ionice is Linux-only (util-linux).

Options worth knowing

A selection, described in our own words. For the full list, see nice(1) or nice --help.

OptionWhat it does
-n, --adjustment NAdd N to the current niceness (default 10); negative values need privileges.

Related