Linux can execute threads simultaneously on different CPU cores and time-share a core among more runnable threads than it can run at once. The scheduler makes those choices according to scheduling policy, priority, affinity, and workload. A nice value is one input for ordinary time-sharing policies.
Processes · Lesson 8
Niceness
Learn how nice values influence CPU scheduling weight for ordinary Linux processes.
Interpreting Nice Values
The conventional nice range is -20 through 19:
- A lower value gives a task greater scheduling weight relative to comparable tasks.
- A higher value makes it “nicer” by giving it less relative weight.
- The default is commonly
0.
Niceness does not reserve a percentage of a CPU or guarantee immediate execution. Its effect is most visible when comparable runnable tasks contend for CPU time. Real-time policies, cgroups, CPU affinity, I/O waits, and other controls can dominate observed behavior.
Under the same ordinary scheduling policy, which nice value gives greater relative CPU weight?
Viewing Niceness
In top, the NI column displays the nice value. You can also request it from ps:
$ ps -o pid,ni,pri,stat,cmd -p 3245
NI is the user-visible nice value. A PRI or similar column can be a derived scheduler priority and its scale varies by tool and scheduling class, so do not assume the two columns are interchangeable.
Which top column normally displays the nice value?
Starting a Command with `nice`
Use nice to launch a new command with an adjusted value:
$ nice -n 5 long-computation
The requested adjustment and accepted syntax can be checked in the local manual. A nonprivileged user can normally make a command nicer by increasing its value. Giving it a lower nice value, and therefore more favorable scheduling weight, requires appropriate privilege or configured resource limits.
What does nice -n 5 long-computation do?
Changing an Existing Process with `renice`
Use renice for an already running process:
$ renice -n 10 -p 3245
This requests nice value 10 for PID 3245. Verify the target first because PIDs can be reused, then confirm the resulting value. Permissions depend on ownership, privilege, resource limits, and system policy. Increasing the nice value is usually allowed for a process you own; reversing that change may not be allowed without privilege.
Which tool changes the nice value of an existing process?
The Manage and Monitor Linux Processes lab offers a controlled environment for viewing and changing nice values. Compare contending CPU-bound tasks rather than expecting a visible difference from an idle system.
Lesson complete
You finished Niceness
You can now interpret and adjust niceness without treating it as a CPU guarantee.
Read lower nice values as greater relative scheduling weight.
Inspect
NIseparately from derived priority fields.Use
nicewhen launching a command.Use
renicefor an existing, verified process.
Keep your learning progress
Create a free account to save this lesson and continue learning on any device.
Create a free account