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.
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.
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.
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
- Only root can lower a nice value. Any user can raise one, including on their own running process.
- Higher number means lower priority. The wording of a question often inverts this deliberately.
- The default nice value for a new process is 0, not -20 and not 10.
- 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
- Which statement about nice values on Linux is correct? machine-checked
- User anna started a job that currently has nice value 10. As anna, she runs `renice 5 -p <pid>` to set its nice value to 5. What happens? machine-checked
- From a shell running at the default nice value of 0, which command starts `./render.sh` with nice value 15 so it competes weakly for CPU time? machine-checked
- As root, type the command that changes the nice value of the already running process with PID 2500 to 10. machine-checked
- A maintenance shell was itself started with `nice -n 5 bash`, so its nice value is 5. Inside that shell you run `nice -n 3 ./convert.sh`. What nice value does convert.sh run with? machine-checked
- You want to confirm the nice value that a running process is actually using, and you would rather not learn a field list by heart. Which ps invocation shows a NI column by default? machine-checked
- You want to know what nice value your current shell is running with, without changing it. Which command prints it? machine-checked
- While watching top you decide that a running process should be given a less favourable nice value, without leaving top. Which interactive key starts that operation? machine-checked
- As root, type the complete command that sets the nice value of every process belonging to the user bob to 15. Identify the target by user name, not by PID. machine-checked
- A shell has been running a data import for some time. You run `renice 10 -p <shell PID>` on the shell itself, but the import process it started earlier keeps running at nice value 0. Why? machine-checked
Practise Process execution priorities