1 .\" Copyright (c) 1980, 1991 The Regents of the University of California.
2 .\" All rights reserved.
4 .\" %%%LICENSE_START(BSD_4_CLAUSE_UCB)
5 .\" Redistribution and use in source and binary forms, with or without
6 .\" modification, are permitted provided that the following conditions
8 .\" 1. Redistributions of source code must retain the above copyright
9 .\" notice, this list of conditions and the following disclaimer.
10 .\" 2. Redistributions in binary form must reproduce the above copyright
11 .\" notice, this list of conditions and the following disclaimer in the
12 .\" documentation and/or other materials provided with the distribution.
13 .\" 3. All advertising materials mentioning features or use of this software
14 .\" must display the following acknowledgement:
15 .\" This product includes software developed by the University of
16 .\" California, Berkeley and its contributors.
17 .\" 4. Neither the name of the University nor the names of its contributors
18 .\" may be used to endorse or promote products derived from this software
19 .\" without specific prior written permission.
21 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 .\" @(#)getpriority.2 6.9 (Berkeley) 3/10/91
36 .\" Modified 1993-07-24 by Rik Faith <faith@cs.unc.edu>
37 .\" Modified 1996-07-01 by Andries Brouwer <aeb@cwi.nl>
38 .\" Modified 1996-11-06 by Eric S. Raymond <esr@thyrsus.com>
39 .\" Modified 2001-10-21 by Michael Kerrisk <mtk.manpages@gmail.com>
40 .\" Corrected statement under EPERM to clarify privileges required
41 .\" Modified 2002-06-21 by Michael Kerrisk <mtk.manpages@gmail.com>
42 .\" Clarified meaning of 0 value for 'who' argument
43 .\" Modified 2004-05-27 by Michael Kerrisk <mtk.manpages@gmail.com>
45 .\" FIXME Oct 2008: Denys Vlasenko is working on a PRIO_THREAD feature that
46 .\" is likely to get included in mainline; this will need to be documented.
48 .TH GETPRIORITY 2 2014-05-10 "Linux" "Linux Programmer's Manual"
50 getpriority, setpriority \- get/set program scheduling priority
52 .B #include <sys/time.h>
54 .B #include <sys/resource.h>
56 .BI "int getpriority(int " which ", id_t " who );
58 .BI "int setpriority(int " which ", id_t " who ", int " prio );
60 The scheduling priority of the process, process group, or user, as
80 is interpreted relative to
82 (a process identifier for
91 denotes (respectively) the calling process, the process group of the
92 calling process, or the real user ID of the calling process.
94 is a value in the range \-20 to 19 (but see the Notes below).
95 The default priority is 0;
96 lower priorities cause more favorable scheduling.
100 call returns the highest priority (lowest numerical value)
101 enjoyed by any of the specified processes.
104 call sets the priorities of all of the specified processes
105 to the specified value.
106 Only the superuser may lower priorities.
110 can legitimately return the value \-1, it is necessary
111 to clear the external variable
114 call, then check it afterward to determine
115 if \-1 is an error or a legitimate value.
118 call returns 0 if there is no error, or
131 No process was located using the
137 In addition to the errors indicated above,
142 The caller attempted to lower a process priority, but did not
143 have the required privilege (on Linux: did not have the
146 Since Linux 2.6.12, this error occurs only if the caller attempts
147 to set a process priority outside the range of the
149 soft resource limit of the target process; see
154 A process was located, but its effective user ID did not match
155 either the effective or the real user ID of the caller,
156 and was not privileged (on Linux: did not have the
161 SVr4, 4.4BSD (these function calls first appeared in 4.2BSD),
166 inherits its parent's nice value.
167 The nice value is preserved across
170 The degree to which their relative nice value affects the scheduling of
171 processes varies across UNIX systems, and,
172 on Linux, across kernel versions.
173 Starting with kernel 2.6.23, Linux adopted an algorithm that causes
174 relative differences in nice values to have a much stronger effect.
175 This causes very low nice values (+19) to truly provide little CPU
176 to a process whenever there is any other
177 higher priority load on the system,
178 and makes high nice values (\-20) deliver most of the CPU to applications
179 that require it (e.g., some audio applications).
181 The details on the condition for
183 depend on the system.
184 The above description is what POSIX.1-2001 says, and seems to be followed on
185 all System\ V-like systems.
186 Linux kernels before 2.6.12 required the real or
187 effective user ID of the caller to match
188 the real user of the process \fIwho\fP (instead of its effective user ID).
189 Linux 2.6.12 and later require
190 the effective user ID of the caller to match
191 the real or effective user ID of the process \fIwho\fP.
192 All BSD-like systems (SunOS 4.1.3, Ultrix 4.2,
193 4.3BSD, FreeBSD 4.3, OpenBSD-2.5, ...) behave in the same
194 manner as Linux 2.6.12 and later.
196 The actual priority range varies between kernel versions.
197 Linux before 1.3.36 had \-infinity..15.
198 Since kernel 1.3.43, Linux has the range \-20..19.
199 On some other systems, the range of nice values is \-20..20.
203 is not required these days, but increases portability.
208 structure with fields of type
213 .SS C library/kernel ABI differences
214 Within the kernel, nice values are actually represented
215 using the corresponding range 40..1
216 (since negative numbers are error codes) and these are the values
222 The glibc wrapper functions for these system calls handle the
223 translations between the user-land and kernel representations
224 of the nice value according to the formula
225 .IR "unice\ =\ 20\ \-\ knice" .
227 According to POSIX, the nice value is a per-process setting.
228 However, under the current Linux/NPTL implementation of POSIX threads,
229 the nice value is a per-thread attribute:
230 different threads in the same process can have different nice values.
231 Portable applications should avoid relying on the Linux behavior,
232 which may be made standards conformant in the future.
237 .BR capabilities (7),
240 .I Documentation/scheduler/sched-nice-design.txt
241 in the Linux kernel source tree (since Linux 2.6.23)