Priority (PR) for a non-real time process is calculated by adding the 20 and nice(NI) value. The nice value ranges from -20 to 19 where the -20 denotes the highest priority and 19 denotes the lowest priority.
PR (0..39) = 20 + NI (-20 ... 19)
0 = 20 + (-20) ====> *highest priority range start (2)*
.
4 = 20 + (-16) ====> *highest priority range end (2)*
5 = 20 + (-15) ====> *Above normal priority range start (1)*
.
14 = 20 + (-6) =====> *Above Normal (1)*
15 = 20 + (-5) =====> *Normal priority range start(0)*
.
20 = 20 + 0 =====> *default priority*
.
24 = 20 + 4 =====> *Normal (0)*
25 = 20 + 5 =====> *below normal priority range start(-1)*
.
34 = 20 + 14 =====> *below normal priority range end (-1)*
35 = 20 + 15 =====> *lowest priority range start(-2)*
.
39 = 20 + 19 ====> *lowest priority range end (-2)*
Mapping between nice value & Win32 Priority
-20 to -16 THREAD_PRIORITY_HIGHEST (2)
-15 to -6 THREAD_PRIORITY_ABOVE_NORMAL (1)
-5 to +4 THREAD_PRIORITY_NORMAL (0)
+5 to +14 THREAD_PRIORITY_BELOW_NORMAL (-1)
+15 to +19 THREAD_PRIORITY_LOWEST (-2)
Do we have any pre-defined conversion method or logic or formula to convert the win32 priority to Linux nice value?
For example, if the priority is THREAD_PRIORITY_NORMAL (0), I want to get either of the values in the range from -5 to 4. Similarly, if the Win32 priority is THREAD_PRIORITY_BELOW_NORMAL (-1), I want to get either of the values in the range from +5 to +14