getpriority(), setpriority() - get or set process' nice value
#include <sys/resource.h>
int getpriority(int which, id_t who)
int setpriority(int which, id_t who, int value)
The getpriority(2) call returns the current nice value for a process, process group, or a user. The returned nice value is in the range of [-NZERO, NZERO-1], where NZERO is the default process priority. (This is the value that would be set with setpriority(2) minus NZERO.)
The setpriority(2) call sets the current nice value for a process, process group, or a user to the value of value + NZERO.
For both calls, the target processes are identified by the which and who arguments: which is one of PRIO_PROCESS, PRIO_PGRP, or PRIO_USER (indicating a process, a process group, and a user, respectively); the who argument is the process ID, process group ID, or effective user ID, depending upon the value of which. If who is 0, it indicates the current process, process group, or user.
The third argument to setpriority(2) is value, the new nice value. This is an integer in the range of [0, 2*NZERO-1]. If value is too low, the nice value is set to the lowest possible value; if value is too high, the nice value is set to the highest possible value. Lower values cause better scheduling. However, only a process with appropriate privileges can lower its own nice value.
Since -1 is a valid return value for getpriority(2), set errno to 0 before calling getpriority(2); then, if getpriority(2) returns -1, check to see if errno is non-zero.
If it succeeds, the getpriority(2) call returns a value in the range of [-NZERO, NZERO-1], which is the nice value of the target process, process group, or user. If it fails, the getpriority(2) call returns -1 and sets errno to indicate the error.
The setpriority(2) call returns 0 on successful completion. Otherwise, it returns -1 and sets errno to indicate the error.
The getpriority(2) and setpriority(2) calls can fail for these reasons:
The setpriority(2) call can also fail for these reasons:
nice(1)
renice(1)
nice(3)