What Does NI Mean in htop?
The NI column in the htop Linux
command-line utility stands for Nice value, which
represents a process’s scheduling priority. This article provides a
quick overview of what this metric means, how it influences CPU resource
allocation, and how system administrators can modify it to optimize
system performance.
Understanding the Nice Value (NI)
In Linux operating systems, the kernel’s scheduler determines how much CPU time each running process receives. The NI column displays a user-space priority indicator ranging from -20 to 19.
Contrary to what might seem intuitive, a lower number means a higher priority. The term “nice” comes from the idea of how polite or “nice” a process is being to other processes on the system:
- Negative High Priority (-20 to -1): A process with a negative nice value is considered “not nice.” It aggressively requests CPU time, pushing other processes aside. Only the root user can assign negative nice values.
- Zero Neutral Priority (0): This is the default nice value for almost all standard processes started by users.
- Positive Low Priority (1 to 19): A process with a positive nice value is being “nice” to the system. It willingly yields CPU cycles to other tasks, making it ideal for background operations.
The Relationship Between NI and PRI
While looking at htop, you will notice the
PRI (Priority) column right next to the
NI column. They are directly related but represent
different things:
- PRI is the actual priority used by the Linux kernel scheduler.
- NI is the user-controlled modifier that influences that priority.
The mathematical relationship in standard Linux environments generally follows this formula:
$$ = 20 + $$
Because the kernel’s internal priority scale usually maps from 0
(highest) to 39 (lowest), a default process with an NI of 0
will have a PRI of 20. If you lower the nice value to
-20, the PRI drops to 0, granting it the
highest possible scheduling priority.
How to Modify the NI Value in htop
One of the main advantages of using htop over the
traditional top command is the ability to interactively
change a process’s nice value on the fly, a process known as
renicing.
- Navigate to the target process using the Up and Down arrow keys.
- To increase the nice value (lower the priority),
press F7 or
[. - To decrease the nice value (raise the priority),
press F8 or
]. Note that reducing the nice value below0requireshtopto be running with root/sudo privileges.