PR is the priority level. The lower the PR, the higher the priority of the process will be.
PR is calculated as follows:
- for normal processes: PR = 20 + NI (NI is nice and ranges from -20 to
- for real time processes: PR = - 1 - real_time_priority
(real_time_priority ranges from 1 to 99)
There are 2 types of processes, the normal ones and the real time
For the normal ones (and only for those), nice is applied as follows:
The "niceness" scale goes from -20 to 19, whereas -20 is the highest priority and 19 the lowest priority. The priority level is calculated as follows:
PR = 20 + NI
Where NI is the nice level and PR is the priority level. So as we can see, the -20 actually maps to 0, while the 19 maps to 39.
By default, a program nice value is 0, but it is possible for the root user to launch programs with a specified nice value by using the following command:
nice -n <nice_value> ./myProgram
We could go even further. The nice priority is actually used for user programs. Whereas the UNIX/LINUX overall priority has a range of 140 values, nice value enables the process to map to the last part of the range (from 100 to 139). This equation leaves the values from 0 to 99 unreachable which will correspond to a negative PR level (from -100 to -1). To be able to access to those values, the process should be stated as "real time".
There are 5 scheduling policies in a LINUX environment that can be displayed with the following command:
Which will show the following list:
1. SCHED_OTHER the standard round-robin time-sharing policy
2. SCHED_BATCH for "batch" style execution of processes
3. SCHED_IDLE for running very low priority background jobs.
4. SCHED_FIFO a first-in, first-out policy
5. SCHED_RR a round-robin policy
The scheduling processes could be divided into 2 groups, the normal scheduling policies (1 to 3) and the real time scheduling policies (4 and 5).
The real time processes will always have priority over normal processes. A real time process could be called using the following command (The example is how to declare a SCHED_RR policy):
chrt --rr <priority between 1-99> ./myProgram
To obtain the PR value for a real time process the following equation is applied:
PR = -1 - rt_prior
Where rt_prior corresponds to the priority between 1 and 99. For that reason the process which will have the higher priority over other processes will be the one called with the number 99.
It is important to note that for real time processes, the nice value is not used.
To see the current "niceness" and PR value of a process the following command can be executed:
Which shows the following output:
In the figure the PR and NI values are displayed. It is good to note the process with PR value -51 that corresponds to a real time value. There are also some processes whose PR value is stated as "rt". This value actually corresponds to a PR value of -100.