getpriority() — Get process scheduling priority

Standards

Standards / Extensions C or C++ Dependencies

XPG4.2
Single UNIX Specification, Version 3

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.

Processes are specified by the values of the which and who arguments. The which argument may be any one of the following set of symbols defined in the sys/resource.h include file:
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.

If unsuccessful, getpriority() returns -1 and sets errno to one of the following values:
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.

Related information