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              either  the effective or the real user ID of the caller, and was
71              not privileged (on Linux: did not have the CAP_SYS_NICE capabil‐
72              ity).  But see NOTES below.
73

CONFORMING TO

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

NOTES

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

BUGS

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

SEE ALSO

120       nice(1), renice(1), fork(2), capabilities(7), sched(7)
121
122       Documentation/scheduler/sched-nice-design.txt  in  the   Linux   kernel
123       source tree (since Linux 2.6.23)
124

COLOPHON

126       This  page  is  part of release 5.10 of the Linux man-pages project.  A
127       description of the project, information about reporting bugs,  and  the
128       latest     version     of     this    page,    can    be    found    at
129       https://www.kernel.org/doc/man-pages/.
130
131
132
133Linux                             2017-09-15                    GETPRIORITY(2)
Impressum