1GETPRIORITY(2)             Linux Programmer's Manual            GETPRIORITY(2)
2
3
4

NAME

6       getpriority, setpriority - get/set program scheduling priority
7

SYNOPSIS

9       #include <sys/time.h>
10       #include <sys/resource.h>
11
12       int getpriority(int which, id_t who);
13       int setpriority(int which, id_t who, int prio);
14

DESCRIPTION

16       The  scheduling priority of the process, process group, or user, as in‐
17       dicated by which and who is obtained with the  getpriority()  call  and
18       set  with  the setpriority() call.  The process attribute dealt with by
19       these system calls is the same attribute  (also  known  as  the  "nice"
20       value) that is dealt with by nice(2).
21
22       The  value  which  is one of PRIO_PROCESS, PRIO_PGRP, or PRIO_USER, and
23       who  is  interpreted  relative  to  which  (a  process  identifier  for
24       PRIO_PROCESS, process group identifier for PRIO_PGRP, and a user ID for
25       PRIO_USER).  A zero value for who denotes  (respectively)  the  calling
26       process,  the process group of the calling process, or the real user ID
27       of the calling process.
28
29       The prio argument is a value in the range -20 to 19 (but see NOTES  be‐
30       low).  with -20 being the highest priority and 19 being the lowest pri‐
31       ority.  Attempts to set a priority  outside  this  range  are  silently
32       clamped  to  the range.  The default priority is 0; lower values give a
33       process a higher scheduling priority.
34
35       The getpriority() call returns the highest priority  (lowest  numerical
36       value)  enjoyed  by  any of the specified processes.  The setpriority()
37       call sets the priorities of all of the specified processes to the spec‐
38       ified value.
39
40       Traditionally,  only  a  privileged  process could lower the nice value
41       (i.e., set a higher priority).  However, since Linux 2.6.12, an unpriv‐
42       ileged process can decrease the nice value of a target process that has
43       a suitable RLIMIT_NICE soft limit; see getrlimit(2) for details.
44

RETURN VALUE

46       On success, getpriority() returns  the  calling  thread's  nice  value,
47       which may be a negative number.  On error, it returns -1 and sets errno
48       to indicate the cause of the error.
49
50       Since a successful call to getpriority() can  legitimately  return  the
51       value -1, it is necessary to clear the external variable errno prior to
52       the call, then check errno afterward to determine if -1 is an error  or
53       a legitimate value.
54
55       setpriority()  returns  0 on success.  On error, it returns -1 and sets
56       errno to indicate the cause of the error.
57

ERRORS

59       EINVAL which was not one of PRIO_PROCESS, PRIO_PGRP, or PRIO_USER.
60
61       ESRCH  No process was located using the which and who values specified.
62
63       In addition to the errors indicated above, setpriority() may fail if:
64
65       EACCES The caller attempted to set a lower nice value (i.e.,  a  higher
66              process  priority),  but did not have the required privilege (on
67              Linux: did not have the CAP_SYS_NICE capability).
68
69       EPERM  A process was located, but its effective user ID did  not  match
70