1 .\" Copyright (c) 1980, 1991 The Regents of the University of California.
2 .\" All rights reserved.
4 .\" SPDX-License-Identifier: BSD-4-Clause-UC
6 .\" @(#)getpriority.2 6.9 (Berkeley) 3/10/91
8 .\" Modified 1993-07-24 by Rik Faith <faith@cs.unc.edu>
9 .\" Modified 1996-07-01 by Andries Brouwer <aeb@cwi.nl>
10 .\" Modified 1996-11-06 by Eric S. Raymond <esr@thyrsus.com>
11 .\" Modified 2001-10-21 by Michael Kerrisk <mtk.manpages@gmail.com>
12 .\" Corrected statement under EPERM to clarify privileges required
13 .\" Modified 2002-06-21 by Michael Kerrisk <mtk.manpages@gmail.com>
14 .\" Clarified meaning of 0 value for 'who' argument
15 .\" Modified 2004-05-27 by Michael Kerrisk <mtk.manpages@gmail.com>
17 .TH GETPRIORITY 2 2022-09-09 "Linux man-pages (unreleased)"
19 getpriority, setpriority \- get/set program scheduling priority
22 .RI ( libc ", " \-lc )
25 .B #include <sys/resource.h>
27 .BI "int getpriority(int " which ", id_t " who );
28 .BI "int setpriority(int " which ", id_t " who ", int " prio );
31 The scheduling priority of the process, process group, or user, as
41 The process attribute dealt with by these system calls is
42 the same attribute (also known as the "nice" value) that is dealt with by
54 is interpreted relative to
56 (a process identifier for
65 denotes (respectively) the calling process, the process group of the
66 calling process, or the real user ID of the calling process.
70 argument is a value in the range \-20 to 19 (but see NOTES below),
71 with \-20 being the highest priority and 19 being the lowest priority.
72 Attempts to set a priority outside this range
73 are silently clamped to the range.
74 The default priority is 0;
75 lower values give a process a higher scheduling priority.
79 call returns the highest priority (lowest numerical value)
80 enjoyed by any of the specified processes.
83 call sets the priorities of all of the specified processes
84 to the specified value.
86 Traditionally, only a privileged process could lower the nice value
87 (i.e., set a higher priority).
88 However, since Linux 2.6.12, an unprivileged process can decrease
89 the nice value of a target process that has a suitable
97 returns the calling thread's nice value, which may be a negative number.
98 On error, it returns \-1 and sets
100 to indicate the error.
102 Since a successful call to
104 can legitimately return the value \-1, it is necessary
110 afterward to determine
111 if \-1 is an error or a legitimate value.
114 returns 0 on success.
115 On failure, it returns \-1 and sets
117 to indicate the error.
121 The caller attempted to set a lower nice value
122 (i.e., a higher process priority), but did not
123 have the required privilege (on Linux: did not have the
136 A process was located, but its effective user ID did not match
137 either the effective or the real user ID of the caller,
138 and was not privileged (on Linux: did not have the
144 No process was located using the
150 POSIX.1-2001, POSIX.1-2008,
151 SVr4, 4.4BSD (these interfaces first appeared in 4.2BSD).
153 For further details on the nice value, see
157 the addition of the "autogroup" feature in Linux 2.6.38 means that
158 the nice value no longer has its traditional effect in many circumstances.
164 inherits its parent's nice value.
165 The nice value is preserved across
168 The details on the condition for
170 depend on the system.
171 The above description is what POSIX.1-2001 says, and seems to be followed on
172 all System\ V-like systems.
173 Linux kernels before 2.6.12 required the real or
174 effective user ID of the caller to match
175 the real user of the process \fIwho\fP (instead of its effective user ID).
176 Linux 2.6.12 and later require
177 the effective user ID of the caller to match
178 the real or effective user ID of the process \fIwho\fP.
179 All BSD-like systems (SunOS 4.1.3, Ultrix 4.2,
180 4.3BSD, FreeBSD 4.3, OpenBSD-2.5, ...) behave in the same
181 manner as Linux 2.6.12 and later.
183 .SS C library/kernel differences
184 The getpriority system call returns nice values translated to the range 40..1,
185 since a negative return value would be interpreted as an error.
186 The glibc wrapper function for
188 translates the value back according to the formula
189 .I unice\~=\~20\~\-\~knice
190 (thus, the 40..1 range returned by the kernel
191 corresponds to the range \-20..19 as seen by user space).
193 According to POSIX, the nice value is a per-process setting.
194 However, under the current Linux/NPTL implementation of POSIX threads,
195 the nice value is a per-thread attribute:
196 different threads in the same process can have different nice values.
197 Portable applications should avoid relying on the Linux behavior,
198 which may be made standards conformant in the future.
203 .BR capabilities (7),
206 .I Documentation/scheduler/sched\-nice\-design.txt
207 in the Linux kernel source tree (since Linux 2.6.23)