The nice( ) system call affects only the process that invokes it. Two other system calls, denoted as getpriority( ) and setpriority( ), act on the base priorities of all processes in a given group. getpriority( ) returns 20 minus the lowest nice field value among all processes in a given group—that is, the highest priority among that processes; setpriority( ) sets the base priority of all processes in a given group to a given value.
The kernel implements these system calls by means of the sys_getpriority( ) and sys_setpriority( ) service routines. Both of them act essentially on the same group of parameters:
Selects the processes according to their process ID (pid field of the process descriptor).
Selects the processes according to their group ID (pgrp field of the process descriptor).
Selects the processes according to their user ID (uid field of the process descriptor).
The value of the pid, pgrp, or uid field (depending on the value of which) to be used for selecting the processes. If who is 0, its value is set to that of the corresponding field of the current process.
The new base priority value (needed only by sys_setpriority( )). It should range between - 20 (highest priority) and + 19 (lowest priority).
As stated before, only processes with a cap_sys_nice capability are allowed to increase their own base priority or to modify that of other processes.
As we saw in Chapter 9, system calls return a negative value only if some error occurred. For this reason, getpriority( ) does not return a normal nice value ranging between -20 and + 19, but rather a nonnegative value ranging between 1 and 40.
Was this article helpful?