]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man2/getpriority.2
Many pages: Fix style issues reported by `make lint-groff`
[thirdparty/man-pages.git] / man2 / getpriority.2
CommitLineData
fea681da
MK
1.\" Copyright (c) 1980, 1991 The Regents of the University of California.
2.\" All rights reserved.
3.\"
47009d5e 4.\" SPDX-License-Identifier: BSD-4-Clause-UC
fea681da
MK
5.\"
6.\" @(#)getpriority.2 6.9 (Berkeley) 3/10/91
7.\"
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>
c11b1abf 11.\" Modified 2001-10-21 by Michael Kerrisk <mtk.manpages@gmail.com>
fea681da 12.\" Corrected statement under EPERM to clarify privileges required
c11b1abf 13.\" Modified 2002-06-21 by Michael Kerrisk <mtk.manpages@gmail.com>
fea681da 14.\" Clarified meaning of 0 value for 'who' argument
c11b1abf 15.\" Modified 2004-05-27 by Michael Kerrisk <mtk.manpages@gmail.com>
fea681da 16.\"
6e00b7a8 17.TH GETPRIORITY 2 2021-08-27 "Linux" "Linux Programmer's Manual"
fea681da
MK
18.SH NAME
19getpriority, setpriority \- get/set program scheduling priority
a29a8b6a
AC
20.SH LIBRARY
21Standard C library
8fc3b2cf 22.RI ( libc ", " \-lc )
fea681da 23.SH SYNOPSIS
c7db92b9 24.nf
fea681da 25.B #include <sys/resource.h>
68e4db0a 26.PP
9f9bbc5a 27.BI "int getpriority(int " which ", id_t " who );
9f9bbc5a 28.BI "int setpriority(int " which ", id_t " who ", int " prio );
c7db92b9 29.fi
fea681da
MK
30.SH DESCRIPTION
31The scheduling priority of the process, process group, or user, as
32indicated by
33.I which
34and
35.I who
36is obtained with the
e511ffb6 37.BR getpriority ()
fea681da 38call and set with the
e511ffb6 39.BR setpriority ()
fea681da 40call.
653c1fe2
MK
41The process attribute dealt with by these system calls is
42the same attribute (also known as the "nice" value) that is dealt with by
43.BR nice (2).
efeece04 44.PP
fea681da
MK
45The value
46.I which
47is one of
48.BR PRIO_PROCESS ,
49.BR PRIO_PGRP ,
50or
51.BR PRIO_USER ,
c13182ef 52and
fea681da 53.I who
c13182ef 54is interpreted relative to
fea681da
MK
55.I which
56(a process identifier for
57.BR PRIO_PROCESS ,
58process group
59identifier for
60.BR PRIO_PGRP ,
61and a user ID for
62.BR PRIO_USER ).
63A zero value for
64.I who
65denotes (respectively) the calling process, the process group of the
66calling process, or the real user ID of the calling process.
efeece04 67.PP
b17796b9
MK
68The
69.I prio
03659d7d 70argument is a value in the range \-20 to 19 (but see NOTES below),
40fcb004 71with \-20 being the highest priority and 19 being the lowest priority.
26ea000d
MK
72Attempts to set a priority outside this range
73are silently clamped to the range.
fea681da 74The default priority is 0;
b8bc577b 75lower values give a process a higher scheduling priority.
efeece04 76.PP
fea681da 77The
e511ffb6 78.BR getpriority ()
fea681da 79call returns the highest priority (lowest numerical value)
c13182ef
MK
80enjoyed by any of the specified processes.
81The
e511ffb6 82.BR setpriority ()
fea681da 83call sets the priorities of all of the specified processes
c13182ef 84to the specified value.
efeece04 85.PP
f69c2584
MK
86Traditionally, only a privileged process could lower the nice value
87(i.e., set a higher priority).
88However, since Linux 2.6.12, an unprivileged process can decrease
89the nice value of a target process that has a suitable
1ae6b2c7 90.B RLIMIT_NICE
f69c2584
MK
91soft limit; see
92.BR getrlimit (2)
93for details.
47297adb 94.SH RETURN VALUE
268c2817
MK
95On success,
96.BR getpriority ()
97returns the calling thread's nice value, which may be a negative number.
98On error, it returns \-1 and sets
99.I errno
855d489a 100to indicate the error.
fe276432 101.PP
268c2817 102Since a successful call to
e511ffb6 103.BR getpriority ()
fea681da 104can legitimately return the value \-1, it is necessary
ba50f49c 105to clear
fea681da
MK
106.I errno
107prior to the
61d6b66a
MK
108call, then check
109.I errno
110afterward to determine
84811e86 111if \-1 is an error or a legitimate value.
efeece04 112.PP
e511ffb6 113.BR setpriority ()
a6bdf7ee 114returns 0 on success.
cb6a894e 115On failure, it returns \-1 and sets
a6bdf7ee 116.I errno
cb6a894e 117to indicate the error.
fea681da
MK
118.SH ERRORS
119.TP
18ce9c4a
MK
120.B EACCES
121The caller attempted to set a lower nice value
122(i.e., a higher process priority), but did not
123have the required privilege (on Linux: did not have the
124.B CAP_SYS_NICE
125capability).
126.TP
fea681da
MK
127.B EINVAL
128.I which
129was not one of
130.BR PRIO_PROCESS ,
131.BR PRIO_PGRP ,
132or
133.BR PRIO_USER .
134.TP
eab64696
MK
135.B EPERM
136A process was located, but its effective user ID did not match
137either the effective or the real user ID of the caller,
138and was not privileged (on Linux: did not have the
139.B CAP_SYS_NICE
140capability).
141But see NOTES below.
18ce9c4a
MK
142.TP
143.B ESRCH
144No process was located using the
145.I which
146and
147.I who
148values specified.
47297adb 149.SH CONFORMING TO
226acd20 150POSIX.1-2001, POSIX.1-2008,
893922a2 151SVr4, 4.4BSD (these interfaces first appeared in 4.2BSD).
fea681da 152.SH NOTES
45fcd0e2
MK
153For further details on the nice value, see
154.BR sched (7).
efeece04 155.PP
ccc12700
MK
156.IR Note :
157the addition of the "autogroup" feature in Linux 2.6.38 means that
158the nice value no longer has its traditional effect in many circumstances.
159For details, see
160.BR sched (7).
efeece04 161.PP
2cab31c6
MK
162A child created by
163.BR fork (2)
164inherits its parent's nice value.
c13182ef
MK
165The nice value is preserved across
166.BR execve (2).
efeece04 167.PP
682edefb 168The details on the condition for
0daa9e92 169.B EPERM
682edefb 170depend on the system.
97c1eac8 171The above description is what POSIX.1-2001 says, and seems to be followed on
efbfd7ec 172all System\ V-like systems.
c13182ef 173Linux kernels before 2.6.12 required the real or
614f40af 174effective user ID of the caller to match
fea681da 175the real user of the process \fIwho\fP (instead of its effective user ID).
614f40af 176Linux 2.6.12 and later require
fea681da
MK
177the effective user ID of the caller to match
178the real or effective user ID of the process \fIwho\fP.
614f40af 179All BSD-like systems (SunOS 4.1.3, Ultrix 4.2,
c13182ef 1804.3BSD, FreeBSD 4.3, OpenBSD-2.5, ...) behave in the same
74aace8a 181manner as Linux 2.6.12 and later.
0ebe771f 182.\"
0722a578 183.SS C library/kernel differences
d818502d 184Within the kernel, nice values are actually represented
8d0641ea 185using the range 40..1
d818502d
MK
186(since negative numbers are error codes) and these are the values
187employed by the
e511ffb6 188.BR setpriority ()
d818502d 189and
e511ffb6 190.BR getpriority ()
d818502d
MK
191system calls.
192The glibc wrapper functions for these system calls handle the
193translations between the user-land and kernel representations
194of the nice value according to the formula
195.IR "unice\ =\ 20\ \-\ knice" .
b0ce4533 196(Thus, the kernel's 40..1 range corresponds to the
8d0641ea 197range \-20..19 as seen by user space.)
24936448
MK
198.SH BUGS
199According to POSIX, the nice value is a per-process setting.
200However, under the current Linux/NPTL implementation of POSIX threads,
201the nice value is a per-thread attribute:
202different threads in the same process can have different nice values.
203Portable applications should avoid relying on the Linux behavior,
204which may be made standards conformant in the future.
47297adb 205.SH SEE ALSO
fea681da 206.BR nice (1),
3e5c319e 207.BR renice (1),
fea681da 208.BR fork (2),
645e6d64
MK
209.BR capabilities (7),
210.BR sched (7)
efeece04 211.PP
b49c2acb 212.I Documentation/scheduler/sched\-nice\-design.txt
173fe7e7 213in the Linux kernel source tree (since Linux 2.6.23)