Course contentsShow
← Linux
Lesson 473 of 1,8195. Process Management and SignalingFree lesson

Process Priority and Nice Values

Examine how priority influences the scheduler's decision-making process.

In this lesson, you will learn how the Linux scheduler uses "nice" values to determine which processes get the most attention from your CPU.

The Scheduler’s Balancing Act

Imagine your CPU is a busy chef in a kitchen. At any given moment, dozens of processes (the "orders") are waiting to be cooked. The kernel’s scheduler is the head chef, deciding which task gets access to the CPU next. To make this decision, it looks at the priority of each process.

While the kernel handles complex internal priority calculations, it allows users to influence this behavior using the nice value.

Understanding "Nice"

The term "nice" is actually quite intuitive:

  • High niceness (+19): You are being very "nice" to other processes by letting them go first, meaning your process gets a lower priority.
  • Low/Negative niceness (-20): You are being "not nice" (selfish), demanding more attention from the CPU and raising your priority.

The range for nice values spans from -20 (highest priority) to 19 (lowest priority). By default, most processes start with a nice value of 0.

How the Scheduler Decides

When the scheduler looks at the list of ready-to-run processes, it favors those that haven't had much "CPU time" recently or those with a higher priority (lower nice value).

If you have a resource-heavy task, like video rendering, you might choose to "renice" it to a higher value. This tells the scheduler: "Don't prioritize this task; let the system's background tasks stay responsive first."

You can see these values using the top or ps commands:

# View the NI (nice) column for all processes
ps -eo pid,ni,cmd | head

In the output, you will see the NI column. If a process is working hard but you want the system to remain smooth for your terminal usage, increasing the nice value of that background process prevents it from "hogging" the CPU cycles needed by your interactive shell. The scheduler will simply pick the "less nice" (lower value) processes more frequently during the next cycle.

Key Takeaway: The Linux scheduler uses nice values as a hint system, where lower values grant a process more CPU priority, and higher values encourage a process to defer to others.