9.2 Adjust Process Scheduling
Key Takeaways
- Nice values range from -20 (highest priority) to 19 (lowest); the default is usually 0—higher nice means nicer to others (less CPU favor).
- Start a process with a nice value using nice -n N command; change a running process with renice N -p PID (root required for increases in priority / negative nice).
- Ordinary users may typically only increase nice (lower priority) on their own processes; lowering nice (boost priority) needs privilege.
- Scheduling adjustment is about CPU contention preference, not killing processes or changing systemd unit Enabled state.
- Verify with ps -o pid,ni,comm or top (NI column) that the nice value matches the task before moving on.
9.2 Adjust Process Scheduling
Quick Answer: CPU scheduling preference uses nice values from -20 (favor this process) to 19 (run only when others do not need CPU). Start with
nice -n N command. Change live processes withrenice N -p PID. Confirm the NI column viapsortop. Root can apply aggressive (negative) nice values; unprivileged users are limited.
Where this fits among “operate running systems”
After you can find and kill hot processes (Section 9.1), the next official skill is to adjust process scheduling. On RHEL this means the classic UNIX nice mechanism that biases the kernel's default fair-share CPU scheduler. On RHEL 10 (kernel 6.12) that scheduler is EEVDF (Earliest Eligible Virtual Deadline First), which replaced the older CFS (Completely Fair Scheduler) in upstream Linux 6.6. The nice/renice interface and the -20..19 range are unchanged by that switch. This is not real-time chrt policy work unless a task explicitly goes there (rare on EX200; master nice/renice first).
Typical tasks:
- “Start
/usr/local/bin/batchjobwith nice value 10.” - “Set the nice value of process
report(or PID …) to 5.” - “Ensure the long backup runs at lower priority than interactive work.”
You are changing how hard the process competes for CPU, not stopping it and not configuring tuned profiles (Section 9.3).
Nice value scale
| Nice value | Relative CPU favor |
|---|---|
| -20 | Highest priority (least “nice” to others) |
| 0 | Default for most processes |
| 19 | Lowest priority (most “nice”) |
Mnemonic: A higher nice number is nicer to everyone else—your process yields. A negative nice is aggressive and usually root-only.
Related fields you may see:
| Field | Tool | Meaning |
|---|---|---|
| NI | top, ps -o ni | Nice value |
| PRI | top, ps -o pri | Kernel priority number (derived; do not confuse with nice) |
Do not try to memorize every PRI mapping. EX200 wording almost always says nice value or “priority” in the nice sense—set NI correctly.
Starting processes with nice
nice command
# default nice when using nice without -n is typically +10 on many systems
nice -n 10 /usr/local/bin/batchjob
nice -n 19 tar czf /backup/home.tgz /home
sudo nice -n -5 /usr/local/bin/urgent-job
Notes:
niceapplies to the command you start and is inherited by children unless they renice themselves.- Without
-n, traditional behavior starts at nice 10 (checkman niceon the exam host if unsure)—always pass-nexplicitly on the exam so the value is unambiguous. - Background example:
nice -n 15 longtask.sh > /var/tmp/longtask.log 2>&1 &
Changing running processes with renice
renice 10 -p 2234
renice -n 10 -p 2234 # GNU form also common
sudo renice -5 -p 2234 # boost priority (negative nice)
renice 5 -u student # all of user's processes (powerful—use carefully)
renice 5 -g 1000 # by process group / GID forms per man page
Prefer PID form on EX200 unless the task says “all processes for user X.”
# Discover then renice
pgrep -a report
# 55201 report
sudo renice 5 -p 55201
ps -o pid,user,ni,comm -p 55201
Permission rules (critical)
| Actor | Typical allowed change |
|---|---|
| Unprivileged user | Raise nice (e.g. 0 → 10) on own processes; cannot renice others’ PIDs |
| Unprivileged user | Cannot lower nice (e.g. 10 → 0 or negative) on modern Linux without privilege |
| Root | Any nice in range on any process |
If renice fails with “Permission denied” or “failed to set priority,” escalate with sudo when the task requires a privileged value or another user’s PID.
Verification
ps -o pid,user,ni,pri,comm -p PID
ps -eo pid,ni,comm --sort=ni | head
top -p PID
# In top, NI column must match the required value
Example success line:
PID USER NI COMMAND
55201 root 5 report
Also:
cat /proc/PID/stat # advanced; nice is among the fields—ps is clearer under time pressure
nice vs kill vs services vs tuned
| Goal | Tool |
|---|---|
| Stop a runaway | kill / pkill (9.1) |
| Change CPU bias of a live job | renice (this section) |
| Start a one-off job softer/harder | nice -n |
| System-wide throughput/latency profile | tuned-adm (9.3) |
| Start unit at boot | systemctl enable (other chapter) |
Do not renice systemd (PID 1) as a “fix.” Do not assume renice persists across process restart: a new process gets default nice unless the launcher uses nice again, a service unit sets Nice=, or a wrapper script applies it.
systemd Nice= (awareness)
Some service units include:
Nice=10
in the unit file. Editing units is a services/deploy skill. For “adjust process scheduling” tasks that name a running process, renice is the direct tool. If a task requires a service to always run niced after reboot, you may need unit drop-ins—read the task; do not invent unit edits when a simple renice satisfies “set nice of this process to N now.”
Real-time scheduling (brief, do not over-study)
chrt -p PID
chrt -f 10 command # SCHED_FIFO example—dangerous if misused
Real-time priorities can starve the system. EX200 study points emphasize nice-style adjustment. Only use chrt if a scenario explicitly demands it. Prefer nice/renice for nearly all practice.
Exam workflows
Workflow 1 — Launch with explicit nice
Task: Run /usr/local/bin/crcscan at nice 15.
nice -n 15 /usr/local/bin/crcscan &
# or foreground if the task expects a long interactive run
pgrep -a crcscan
ps -o pid,ni,comm -C crcscan
Workflow 2 — Fix an already running job
Task: Process datamunch must have nice value 10.
pgrep -a datamunch
sudo renice 10 -p $(pgrep -n datamunch) # -n newest match; confirm only one PID first!
# Safer:
pgrep datamunch
sudo renice 10 -p 44120
ps -o pid,ni,comm -p 44120
Avoid blind $(pgrep ...) if multiple PIDs match—renice accepts multiple -p or run a loop after listing.
for pid in $(pgrep datamunch); do sudo renice 10 -p "$pid"; done
ps -o pid,ni,comm -C datamunch
Workflow 3 — Lower priority without killing
A compile job starves the GUI/SSH interactivity. Soften it:
pgrep -a make
sudo renice 19 -p 3001
The job keeps running; interactive sessions feel better under load.
Workflow 4 — Privileged boost
Task: Set nice of PID 2200 to -10.
sudo renice -10 -p 2200
ps -o pid,ni,comm -p 2200
Without root this fails—use sudo on the exam VM.
Interaction with multi-CPU and load
Nice does not pin a process to a CPU (that is taskset). Nice does not limit memory (systemd-run -p MemoryMax= or cgroups). Nice only tilts CPU time sharing when runnable processes compete. On an idle system, even nice 19 may run at full speed because nothing else wants the CPU—that is normal.
Common traps
- Inverting the scale — thinking 19 is “highest priority.” It is lowest.
- Omitting
-nand assuming the default is 0 when using thenicewrapper (default is often +10). - Renicing once then restarting the app—new PID loses the setting.
- Using
kill -STOPby mistake while trying to “slow” a process—STOP freezes it entirely. - Confusing NI with %CPU — high %CPU can still have NI 0; renice changes preference, not an instant %CPU cap.
- renice without verifying — always re-check
ps -o ni.
Persistence notes
reniceaffects the current process until it exits or is reniced again.- Reboot clears all user-space PIDs; nothing about a one-time renice survives unless the job is started again with
niceor a unit/cronwrapper sets it. - For exam tasks phrased as “set the nice value of this running process,” immediate
renice+ verification is enough. - For “always run this batch at nice 10,” combine scheduling tools (cron/systemd timer) with
nicein the command line—covered more fully under task scheduling objectives.
Section checkpoint
You should explain the -20..19 nice scale, start jobs with nice -n, change live jobs with renice, know when root is required, verify with ps/top NI, and avoid confusing scheduling bias with kill or tuned. That meets the EX200 “adjust process scheduling” study point.
Which nice value gives a process the lowest CPU scheduling priority among common settings?
Which command starts /usr/local/bin/batchjob with an explicit nice value of 10?
An unprivileged user owns PID 4400 at nice 0 and runs renice -5 -p 4400 without sudo. What is the expected result on a normal RHEL system?
After sudo renice 5 -p 55201, which check best confirms success for an EX200 task?