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/resource.h>
10
11       int getpriority(int which, id_t who);
12       int setpriority(int which, id_t who, int prio);
13

DESCRIPTION

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

RETURN VALUE

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

ERRORS

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

CONFORMING TO

73       POSIX.1-2001, POSIX.1-2008, SVr4, 4.4BSD (these  interfaces  first  ap‐
74       peared in 4.2BSD).
75

NOTES

77       For further details on the nice value, see sched(7).
78
79       Note:  the  addition  of  the "autogroup" feature in Linux 2.6.38 means
80       that the nice value no longer has its traditional effect in  many  cir‐
81       cumstances.  For details, see sched(7).
82
83       A  child created by fork(2) inherits its parent's nice value.  The nice
84       value is preserved across execve(2).
85
86       The details on the condition for EPERM depend on the system.  The above
87       description  is what POSIX.1-2001 says, and seems to be followed on all
88       System V-like systems.  Linux kernels before 2.6.12 required  the  real
89       or  effective  user  ID  of  the  caller  to match the real user of the
90       process who (instead of its effective user ID).  Linux 2.6.12 and later
91       require the effective user ID of the caller to match the real or effec‐
92       tive user ID of the process who.  All BSD-like  systems  (SunOS  4.1.3,
93       Ultrix  4.2,  4.3BSD, FreeBSD 4.3, OpenBSD-2.5, ...) behave in the same
94       manner as Linux 2.6.12 and later.
95
96   C library/kernel differences
97       Within the kernel, nice values are actually represented using the range
98       40..1 (since negative numbers are error codes) and these are the values
99       employed by the setpriority()  and  getpriority()  system  calls.   The
100       glibc  wrapper functions for these system calls handle the translations
101       between the user-land and kernel representations of the nice value  ac‐
102       cording  to  the formula unice = 20 - knice.  (Thus, the kernel's 40..1
103       range corresponds to the range -20..19 as seen by user space.)
104

BUGS

106       According to POSIX, the nice value is a per-process setting.   However,
107       under  the current Linux/NPTL implementation of POSIX threads, the nice
108       value is a per-thread attribute: different threads in the same  process
109       can have different nice values.  Portable applications should avoid re‐
110       lying on the Linux behavior, which may be made standards conformant  in
111       the future.
112

SEE ALSO

114       nice(1), renice(1), fork(2), capabilities(7), sched(7)
115
116       Documentation/scheduler/sched-nice-design.txt   in   the  Linux  kernel
117       source tree (since Linux 2.6.23)
118

COLOPHON

120       This page is part of release 5.12 of the Linux  man-pages  project.   A
121       description  of  the project, information about reporting bugs, and the
122       latest    version    of    this    page,    can     be     found     at
123       https://www.kernel.org/doc/man-pages/.
124
125
126
127Linux                             2021-03-22                    GETPRIORITY(2)
Impressum