Process priorities in Linux are critical for system administration and performance tuning. Linux controls process execution priority with the nice value (for user-space) and scheduling priority at the kernel level. These are some of the Linux commands I hardly touch to be honest. Hopefully this short tutorial on process priorities in Linux can help somebody out there.

I was very happy to put this tutorial together after taking a walk in the Greenacre Park in New York City

Default Linux Priority of a Job

Every process has a nice value between -20 (highest priority) and 19 (lowest priority). The default nice value for processes started by normal users is 0.

For example:

ps -o pid,comm,nice -p $$

This shows the PID, command, and nice value of your current shell ($$ is your shell PID).
Output would be:

  PID COMMAND   NI
12345 bash       0

Run a Program with Higher or Lower Priority

You can set the nice value at start with the nice command. Run a command with lower priority (nice value = 10):

nice -n 10 gzip somefile.iso

This makes gzip less demanding on CPU, letting other tasks run faster.

  • Run a command with higher priority (nice value = -5):
    Requires root privileges.
  • This speeds up tar compression by giving it more CPU time.

Change the Priority of a Running Process

Use renice to adjust the nice value of an already running process. Find the PID:

ps -eo pid,comm,nice | grep nginx

Change the nice value:

sudo renice -n -10 -p 1321

-n -10 → set nice value to -10 (higher priority).
-p 1321 → apply to PID 1321.

Check again:

ps -o pid,comm,nice -p 1321

Real-Life Admin Examples

Example 1: Lower priority backup job.

Run backup in background without slowing the server:

nice -n 15 rsync -av /data /backup &

Example 2: Speed up a critical web service.

If a database (mysqld) is slow during high load:

sudo renice -n -5 -p $(pidof mysqld)

Example 3: Batch processing

Give CPU-intensive video encoding lowest priority:

nice -n 19 ffmpeg -i coolmovie.mp4 -c:v libx265 movie-hevc.mp4

Summary

  • Default nice = 0
  • Higher nice = lower priority (19 is lowest).
  • Lower nice (negative) = higher priority (-20 is max).
  • nice → start process with a priority.
  • renice → change priority of a running process.

Support my work by shopping a T-Shirt or coffee mug from my shop. Thanks!

Leave a comment

Your email address will not be published. Required fields are marked *