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
-20 to 19, default 0
  1. Start a long-running process

    sleep infinity &
    pgrep -a sleep
  2. Read its default nice value

    ps -o pid,comm,nice,pri -p $(pgrep -n sleep)
  3. 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)

    PRI moved as well, because the kernel recalculated it.

  4. Lower its priority

    renice -n 5 $(pgrep -n sleep)
    ps -o pid,comm,nice,pri -p $(pgrep -n sleep)

    That one needed no sudo.

  5. Try to raise it without privileges

    renice -n -5 $(pgrep -n sleep)
    renice: failed to set priority for 16872 (process ID): Permission denied
  6. Clean up

    nice sets the value at launch, where renice changes one already running.

    nice -n 15 sleep 60 &
    ps -o pid,comm,nice -p $(pgrep -n sleep)
    pkill sleep
    pgrep -a sleep