Exercise
Managing Nice Values Exercise
Task
Change a running process's priority in both directions, and find the limit an ordinary user runs into.
- Host
servera- Nice range
-
-20to19, default0
-
Start a long-running process
sleep infinity & pgrep -a sleep -
Read its default nice value
ps -o pid,comm,nice,pri -p $(pgrep -n sleep) -
Raise its priority
Lower nice means less nice to everything else, so it competes harder for CPU.
sudo renice -n -10 $(pgrep -n sleep) ps -o pid,comm,nice,pri -p $(pgrep -n sleep)PRImoved as well, because the kernel recalculated it. -
Lower its priority
renice -n 5 $(pgrep -n sleep) ps -o pid,comm,nice,pri -p $(pgrep -n sleep)That one needed no
sudo. -
Try to raise it without privileges
renice -n -5 $(pgrep -n sleep)renice: failed to set priority for 16872 (process ID): Permission denied -
Clean up
nicesets the value at launch, whererenicechanges one already running.nice -n 15 sleep 60 & ps -o pid,comm,nice -p $(pgrep -n sleep) pkill sleep pgrep -a sleep