Process execution priorities

Nice values: the hint you give the scheduler about how much a process matters, the range it lives in, and the asymmetric rule about who may change it in which direction.

Lesson 6 of 8 in objective 103. GNU and Unix commands, part of LPIC-1 Exam 101-500.

Nice values: a higher number is a lower priority. A range from greedy — only root may set one here to generous — any user may. -20. 0: the default. 19. greedy — only root may set one here generous — any user may -20 0 the default 19
Nice values: a higher number is a lower priority.

The scale, and who may move along it

A nice value runs from -20 to 19. Low is greedy and high is generous — a process at 19 is being nice to everyone else and yields CPU readily, a process at -20 hogs it. The default for anything you start is 0. It is a weighting for the scheduler, not a reservation: a niced-down process still runs when nothing else wants the CPU.

The asymmetry is what gets tested. Any user may make their own processes NICER — raise the number — and only root may lower one, whether at start time or afterwards. So a normal user can run nice -n 10 command but nice -n -10 command fails, and the same rule applies to renice on a process already running.

Who may move a nice value, and which way they may move it. A grid of Direction against Who is asking. Raised — nicer, yields CPU: Any user gives Allowed, own processes; root gives Allowed. Lowered — greedier, hogs CPU: Any user gives Refused, at start and after; root gives Allowed. Who is asking → Direction ↓ Any user root Raised — nicer, yields CPU Allowed, own processes Allowed Lowered — greedier, hogs CPU Refused, at start and after Allowed
Who may move a nice value, and which way they may move it.

Setting it before and after

nice starts a command with a given value: nice -n 5 command, or the terse nice -5 command, which means the same thing and is exactly why the negative form reads so confusingly. renice changes a process already running, addressed by PID (-p), by user (-u) or by process group (-g).

To see the current value, top shows a NI column and ps -l shows NI beside PR. PR is the kernel's internal priority, derived from the nice value rather than set directly, so an exam question about "the number you can change" means NI.

A renice line, cut into the value it sets and the process it sets it on. renice 5 -p 1234 — part 1, 5: the new value; only root may lower one; part 2, -p: by PID (-u by user, -g by process group); part 3, 1234: already running — nice would take a command here. renice 1 5 2 -p 3 1234 1 the new value; only root may lower one 2 by PID (-u by user, -g by process group) 3 already running — nice would take a command here
A renice line, cut into the value it sets and the process it sets it on.

Worth carrying in

nice -n 10 cmd
Start a command with nice value 10 — lower priority.
renice 5 -p PID
Change a running process. -u by user, -g by process group.
-20 … 19
The range. -20 is the most favourable, 19 the least.
ps -l
Shows the NI column beside PR.
top
Live NI column; r renices interactively.

What the exam does with this

Objective
103. GNU and Unix commands
Share of the exam
43.33% (the whole objective)
Questions in this lesson
10
Signed for by a person
0

Partly checked. None of the 10 questions here has been read against the cited source by a person. 10 questions have been checked against their cited clause by an automated pass — which is not the same thing, and is not a signature.

Only questions a person has signed for are used in mock exams here. That is the whole difference between the two kinds of checking above.

How these questions are written — where each question comes from, what the verification ledger records, and what happens when one is found wrong.

Drill this lesson

A lesson is one sitting: the trainer draws a short run from these questions alone and spaces the ones you get wrong.

Practise Process execution priorities

Questions in this lesson

Practise Process execution priorities

The rest of objective 103