Standards / Extensions | C or C++ | Dependencies |
---|---|---|
XPG4.2 |
both |
#define _XOPEN_SOURCE_EXTENDED 1
#include <sys/resource.h>
int setpriority(int which, id_t who, int priority);
setpriority() sets the scheduling priority of a process, process group or user.
The who argument specifies the ID (process, process group, or user). A 0 (zero) value for the who argument specifies the current process, process group or user ID.
The priority argument specifies the scheduling priority. It is specified as a signed integer in the range, -20 to 19. Negative priorities cause more favorable scheduling. The default priority is 0. If the value specified to setrlimit() is less than the system's lowest supported priority value, the system's lowest supported value is used; if it is greater than the system's highest supported value, the system's highest supported value is used. The setting of a process's scheduling priority value has the equivalent effect on a process's nice value, since they both represent the process's relative CPU priority. For example, setting one's scheduling priority value to its maximum value (19) has the equivalent effect of increasing one's nice value to its maximum value ((2*NZERO)-1), and will be reflected on the nice(), getpriority() and setpriority() functions.
If more than one process is specified, setpriority() sets the priorities of all of the specified processes to the specified value.
Only a process with appropriate privilege can lower its priority.
If successful, setpriority() returns 0.