setpriority() — Set process scheduling priority
Standards
Standards / Extensions | C or C++ | Dependencies |
---|---|---|
XPG4.2 |
both |
Format
#define _XOPEN_SOURCE_EXTENDED 1
#include <sys/resource.h>
int setpriority(int which, id_t who, int priority);
General description
setpriority() sets the scheduling priority of a process, process group or user.
- PRIO_PROCESS
- indicates that the who argument is to be interpreted as a process ID
- PRIO_PGRP
- indicates that the who argument is to be interpreted as a process group ID
- PRIO_USER
- indicates that the who argument is to be interpreted as a user ID
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.
Returned value
If successful, setpriority() returns 0.
- Error Code
- Description
- EACCES
- The priority is being changed to a lower value and the current process does not have the appropriate privilege.
- EINVAL
- The symbol specified in the which argument was not recognized, or the value of the who argument is not a valid process ID, process group ID or user ID.
- ENOSYS
- The system does not support this function.
- EPERM
- A process was located, but neither the real nor effective user ID of the executing process match the effective user ID of the process whose priority is to be changed.
- ESRCH
- No process could be located using the which and who argument values specified.