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

NAME

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

SYNOPSIS

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

DESCRIPTION

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

RETURN VALUE

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

ERRORS

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

EXAMPLES

96   Using getpriority()
97       The following example returns the current scheduling priority  for  the
98       process ID returned by the call to getpid().
99
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
115           #include <sys/resource.h>
116           ...
117           int which = PRIO_PROCESS;
118           id_t pid;
119           int priority = -20;
120           int ret;
121
122           pid = getpid();
123           ret = setpriority(which, pid, priority);
124

APPLICATION USAGE

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

RATIONALE

133       None.
134

FUTURE DIRECTIONS

136       None.
137

SEE ALSO

139       nice(), sched_get_priority_max(), sched_setscheduler()
140
141       The Base Definitions volume of POSIX.1‐2017, <sys_resource.h>
142
144       Portions of this text are reprinted and reproduced in  electronic  form
145       from  IEEE Std 1003.1-2017, Standard for Information Technology -- Por‐
146       table Operating System Interface (POSIX), The Open Group Base  Specifi‐
147       cations  Issue  7, 2018 Edition, Copyright (C) 2018 by the Institute of
148       Electrical and Electronics Engineers, Inc and The Open Group.   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.opengroup.org/unix/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                  2017                      GETPRIORITY(3P)
Impressum