renice and nice

LPIC-1LINUX

1 renice

In top, you can renice a running process interactively without leaving the program.

Inside top:

  1. Press r

  2. Type the PID of the process you want to renice

  3. Enter the new nice value (from -20 to 19)

Example: if sshd has PID 1234 and you want to lower its priority, press r, type 1234, then type 10.

From the shell:

renice 10 -p 1234 # set nice value of PID 1234 to 10

renice -n 5 -p 1234 # same, explicit -n flag (POSIX form)

renice -n -5 -u myself # change niceness for all processes owned by user myself

renice -n 3 -g mygroup # change niceness for a process group

Key exam points:

  • Range: -20 (highest priority) to 19 (lowest priority)

  • Only root can set a negative value or increase priority of a process (lower the nice value)

  • Any user can lower their own process's priority (raise the nice value), but can't reverse it afterward

  • nice sets the priority at launch of a new process; renice changes it for an already-running process — this distinction comes up often on the exam

  • Default nice value for a new process is 0

2 nice

nice — set priority when starting a new process

nice command # start 'command' with nice value +10 (default increment)

nice -n 15 command # start 'command' with nice value 15

nice -n -5 command # start with higher priority (needs root)

  • If you run nice with no options, it adds 10 to the default niceness (0), so the new process starts at 10.

  • Check a process's current niceness with ps -el or ps -eo pid,ni,comm (the NI column) — or in top, the NI column next to PID.

Quick comparison table (exam-relevant distinction):

Command Applies to When

nice New process At launch

renice Existing process While running

r in top Existing process While running, interactively

Permissions rule (same for both nice and renice):

  • Regular users can only move niceness up (lower priority) — e.g., from 0 to 10.

  • Regular users cannot move niceness down (higher priority) or reverse an increase they made.

  • Only root can set negative values or decrease niceness.

What nice can actually run:

nice can run any executable — a binary command, a shell script, or even a shell builtin invoked via a subshell — as long as it's something the shell can execute.

Actual example:

nice -n 15 tar -czf backup.tar.gz /home/user/data

This starts tar with a nice value of 15 (lower priority), useful for a heavy compression job you don't want hogging the CPU.

With a shell script:

nice -n 10 ./backup.sh # the same as running barely nice

This works exactly the same way — nice doesn't care whether the target is a compiled binary or a script, as long as it's executable (has the shebang line and execute permission, or you invoke it via bash script.sh).

nice -n 10 bash backup.sh # also valid, explicitly invoking bash

Verify it worked, while it's running:

ps -eo pid,ni,comm | grep backup

You'd see 10 in the NI column next to the script's process.

One nuance for the exam: nice sets the niceness for the process it launches — if that process is a shell script that spawns child processes (like tar inside backup.sh), those children normally inherit the nice value from the parent, since niceness is inherited on fork().

Default niceness 0 happens when a process is started normally — by the shell, by a system service manager, by exec(), etc. — without going through the nice command at all. Just typing:

command

starts it at niceness 0 (inherited from the parent shell, which is normally at 0 itself).

To explicitly launch with niceness 0 via nice:

nice -n 0 command

Contact

Email

hello@unixtips.eu

© 2025. All rights reserved.