UPDATE: My undestanding was correct and the man page of ps
has been updated to now state the following for the PRI column: "priority of the process. Higher number means higher priority."
I've been trying to understand how scheduling priorities work in linux. Here's what I've got:
- The kernel uses a priority value for each process which ranges from 0 to 139. The lower the number, the more priority the process has.
- Priority values from 0 to 99 are reserved, all user space processes have a priority from 100 to 139.
- Linux provides the
nice
interface which is the priority exposed to and modifiable by the user. Thenice
value ranges from -20 to 19, and maps to priorities 100 to 139. As with the priority value, the lower thenice
value, the more priority the process has.
My question now is: What does the PRI column of ps
indicate?
The man page of ps
says:
pri PRI priority of the process. Higher number means lower priority.
But the value ranges from 0 to 39, and I empirically determined it is equal to 19 - nice
.
It is impossible, given the relationship, that both nice
and the priority shown in the PRI
column satisfy "higher number means lower priority".
What am I missing?
Example showing this behaviour:
root@kali:~# ps -ao pid,comm,pri,nice
PID COMMAND PRI NI
6153 cat 19 0
(···)
root@kali:~# renice -n -10 -p 6153
6153 (process ID) old priority 0, new priority -10
root@kali:~# ps -ao pid,comm,pri,nice
PID COMMAND PRI NI
6153 cat 29 -10
(···)