Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

getpriority, setpriority - get or set process priority

&pagelevel(4)&pagelevel

Syntax

#include <sys/resource.h>

int getpriority(int which, id_t who);

int setpriority(int which, id_t who, int priority);

Description getpriority() retrieves the current scheduling priority of the process, the process group

or the user.

setpriority() sets the scheduling priority of the process, the process group or the user.

The arguments which and who define which process is addressed. which can take the
following values: PRIO_PROCESS, PRIO_PGRP or PRIO_USER. Depending on this, the
contents of who are interpreted as process ID, process group ID or user ID respectively. A
null value for who denotes the current process, the current process group or the current
user.

getpriority() returns the highest priority (the lowest numerical value) that is claimed by
one of the specified processes. setpriority() sets the priorities of all specified
processes to the value specified via priority.

The default priority is 0; lower priorities mean improved scheduling. If the priority is below
-20, the value -20 is used; if it is over 20, the value 20 is used.

Only users with the appropriate authorization can reduce priorities.

When threads are used, the getpriority() and setpriority() functions affect the
process or a thread in the following manner:

  • Query or set the scheduling priority of the process.

  • If the process is multithreaded, the scheduling priority affects all threads of the process.

Return val.

getpriority():

-20 ≤ return value ≤ 20

if successful.

-1

if an error occurs. errno is set to indicate the error.

setpriority():

0
-1

if successful.
if an error occurs. errno is set to indicate the error.

getpriority() and setpriority() will fail if:

ESRCH

EINVAL

No process was found to which the specified values which and who apply.
which was neither PRIO_PROCESS, PRIO_PGRP nor PRIO_USER, or who did
not contain a valid process ID, process group ID or user ID.

setpriority() can also fail if:

EPERM

A process was found but neither the effective user ID nor the real one
matches the effective user ID of the process whose priority is to be
changed.

EACCES

An attempt was made to set the priority to a lower value, which means a
higher priority, but the current process does not have the appropriate
authorization.

Notes

What effect the changing of the scheduling priority has depends on the algorithm of the
process scheduling.

As getpriority() can legitimately also return the value -1, the external variable errno
must be deleted before the call and then checked to establish whether the value -1 indicates
an error or a permissible value.

See also

nice(), sys/resource.h.