1GETPRIORITY(3P)            POSIX Programmer's Manual           GETPRIORITY(3P)
2
3
4

PROLOG

6       This  manual  page is part of the POSIX Programmer's Manual.  The Linux
7       implementation of this interface may differ (consult the  corresponding
8       Linux  manual page for details of Linux behavior), or the interface may
9       not be implemented on Linux.
10
11

NAME

13       getpriority, setpriority — get and set the nice value
14

SYNOPSIS

16       #include <sys/resource.h>
17
18       int getpriority(int which, id_t who);
19       int setpriority(int which, id_t who, int value);
20

DESCRIPTION

22       The getpriority() function shall obtain the nice value  of  a  process,
23       process  group,  or user. The setpriority() function shall set the nice
24       value of a process, process group, or user to value+{NZERO}.
25
26       Target processes are specified by the values of the which and who argu‐
27       ments.  The  which  argument  may  be  one  of  the  following  values:
28       PRIO_PROCESS, PRIO_PGRP, or PRIO_USER, indicating that the who argument
29       is  to be interpreted as a process ID, a process group ID, or an effec‐
30       tive user ID, respectively. A 0 value for the  who  argument  specifies
31       the current process, process group, or user.
32
33       The  nice value set with setpriority() shall be applied to the process.
34       If the process is multi-threaded, the nice value shall affect all  sys‐
35       tem scope threads in the process.
36
37       If more than one process is specified, getpriority() shall return value
38       {NZERO} less than the lowest nice value pertaining to any of the speci‐
39       fied  processes,  and setpriority() shall set the nice values of all of
40       the specified processes to value+{NZERO}.
41
42       The default nice value is {NZERO}; lower nice values shall  cause  more
43       favorable   scheduling.  While  the  range  of  valid  nice  values  is
44       [0,{NZERO}*2−1], implementations may enforce more  restrictive  limits.
45       If value+{NZERO} is less than the system's lowest supported nice value,
46       setpriority() shall set the nice value to the lowest  supported  value;
47       if  value+{NZERO}  is  greater than the system's highest supported nice
48       value, setpriority() shall set the nice value to the highest  supported
49       value.
50
51       Only a process with appropriate privileges can lower its nice value.
52
53       Any  processes  or  threads using SCHED_FIFO or SCHED_RR shall be unaf‐
54       fected by a call to setpriority().  This is not considered an error.  A
55       process  which  subsequently  reverts  to SCHED_OTHER need not have its
56       priority affected by such a setpriority() call.
57
58       The effect of changing  the  nice  value  may  vary  depending  on  the
59       process-scheduling algorithm in effect.
60
61       Since getpriority() can return the value −1 upon successful completion,
62       it is necessary to set errno to 0 prior to a call to getpriority().  If
63       getpriority() returns the value −1, then errno can be checked to see if
64       an error occurred or if the value is a legitimate nice value.
65

RETURN VALUE

67       Upon successful completion, getpriority() shall return  an  integer  in
68       the  range  −{NZERO} to {NZERO}−1.  Otherwise, −1 shall be returned and
69       errno set to indicate the error.
70
71       Upon successful completion, setpriority() shall return 0; otherwise, −1
72       shall be returned and errno set to indicate the error.
73

ERRORS

75       The getpriority() and setpriority() functions shall fail if:
76
77       ESRCH  No  process  could  be  located using the which and who argument
78              values specified.
79
80       EINVAL The value of the which argument was not recognized, or the value
81              of the who argument is not a valid process ID, process group ID,
82              or user ID.
83
84       In addition, setpriority() may fail if:
85
86       EPERM  A process was located, but neither the real nor  effective  user
87              ID  of  the executing process match the effective user ID of the
88              process whose nice value is being changed.
89
90       EACCES A request was made to change the nice value to a  lower  numeric
91              value  and  the current process does not have appropriate privi‐
92              leges.
93
94       The following sections are informative.
95

EXAMPLES

97   Using getpriority()
98       The following example returns the current scheduling priority  for  the
99       process ID returned by the call to getpid().
100
101           #include <sys/resource.h>
102           ...
103           int which = PRIO_PROCESS;
104           id_t pid;
105           int ret;
106
107           pid = getpid();
108           ret = getpriority(which, pid);
109
110   Using setpriority()
111       The  following  example sets the priority for the current process ID to
112       −20.
113
114           #include <sys/resource.h>
115           ...
116           int which = PRIO_PROCESS;
117           id_t pid;
118           int priority = -20;
119           int ret;
120
121           pid = getpid();
122           ret = setpriority(which, pid, priority);
123

APPLICATION USAGE

125       The getpriority() and setpriority() functions work with an offset  nice
126       value   (nice   value  −{NZERO}).  The  nice  value  is  in  the  range
127       [0,2*{NZERO} −1], while the return  value  for  getpriority()  and  the
128       third  parameter  for  setpriority() are in the range [−{NZERO},{NZERO}
129       −1].
130

RATIONALE

132       None.
133

FUTURE DIRECTIONS

135       None.
136

SEE ALSO

138       nice(), sched_get_priority_max(), sched_setscheduler()
139
140       The Base Definitions volume of POSIX.1‐2008, <sys_resource.h>
141
143       Portions of this text are reprinted and reproduced in  electronic  form
144       from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology
145       -- Portable Operating System Interface (POSIX),  The  Open  Group  Base
146       Specifications Issue 7, Copyright (C) 2013 by the Institute of Electri‐
147       cal and Electronics Engineers,  Inc  and  The  Open  Group.   (This  is
148       POSIX.1-2008  with  the  2013  Technical Corrigendum 1 applied.) In the
149       event of any discrepancy between this version and the original IEEE and
150       The  Open Group Standard, the original IEEE and The Open Group Standard
151       is the referee document. The original Standard can be  obtained  online
152       at http://www.unix.org/online.html .
153
154       Any  typographical  or  formatting  errors that appear in this page are
155       most likely to have been introduced during the conversion of the source
156       files  to  man page format. To report such errors, see https://www.ker
157       nel.org/doc/man-pages/reporting_bugs.html .
158
159
160
161IEEE/The Open Group                  2013                      GETPRIORITY(3P)
Impressum