getpriority() — Get process scheduling priority
Standards
Standards / Extensions | C or C++ | Dependencies |
---|---|---|
XPG4.2 |
both |
Format
#define _XOPEN_SOURCE_EXTENDED 1
#include <sys/resource.h>
int getpriority(int which, id_t who);
General description
getpriority() obtains the current 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.
Returned value
If successful, getpriority() returns the priority of the process, process group, or used ID requested in who. The priority is returned as an integer in the range -20 to 19 (the lower the numerical value, the higher the priority).
If more than one process is specified, getpriority() returns the highest priority pertaining to any of the specified processes.
- Error Code
- Description
- 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.
- ESRCH
- No process could be located using the which and who argument values specified.
Because getpriority() can return the value -1 on successful completion, it is necessary to set the external variable errno to 0 before a call to getpriority(). If getpriority() returns -1, then errno can be checked to see if an error occurred or if the value is a legitimate priority.