]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man2/getpriority.2
Reordered sections to be more consistent, in some cases renaming
[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.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
7.\" 1. Redistributions of source code must retain the above copyright
8.\" notice, this list of conditions and the following disclaimer.
9.\" 2. Redistributions in binary form must reproduce the above copyright
10.\" notice, this list of conditions and the following disclaimer in the
11.\" documentation and/or other materials provided with the distribution.
12.\" 3. All advertising materials mentioning features or use of this software
13.\" must display the following acknowledgement:
14.\" This product includes software developed by the University of
15.\" California, Berkeley and its contributors.
16.\" 4. Neither the name of the University nor the names of its contributors
17.\" may be used to endorse or promote products derived from this software
18.\" without specific prior written permission.
19.\"
20.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30.\" SUCH DAMAGE.
31.\"
32.\" @(#)getpriority.2 6.9 (Berkeley) 3/10/91
33.\"
34.\" Modified 1993-07-24 by Rik Faith <faith@cs.unc.edu>
35.\" Modified 1996-07-01 by Andries Brouwer <aeb@cwi.nl>
36.\" Modified 1996-11-06 by Eric S. Raymond <esr@thyrsus.com>
305a0578 37.\" Modified 2001-10-21 by Michael Kerrisk <mtk-manpages@gmx.net>
fea681da 38.\" Corrected statement under EPERM to clarify privileges required
305a0578 39.\" Modified 2002-06-21 by Michael Kerrisk <mtk-manpages@gmx.net>
fea681da 40.\" Clarified meaning of 0 value for 'who' argument
305a0578 41.\" Modified 2004-05-27 by Michael Kerrisk <mtk-manpages@gmx.net>
fea681da 42.\"
69962544 43.TH GETPRIORITY 2 2002-09-20 "Linux" "Linux Programmer's Manual"
fea681da
MK
44.SH NAME
45getpriority, setpriority \- get/set program scheduling priority
46.SH SYNOPSIS
47.B #include <sys/time.h>
48.br
49.B #include <sys/resource.h>
50.sp
51.BI "int getpriority(int " which ", int " who );
52.br
53.BI "int setpriority(int " which ", int " who ", int " prio );
54.SH DESCRIPTION
55The scheduling priority of the process, process group, or user, as
56indicated by
57.I which
58and
59.I who
60is obtained with the
e511ffb6 61.BR getpriority ()
fea681da 62call and set with the
e511ffb6 63.BR setpriority ()
fea681da
MK
64call.
65
66The value
67.I which
68is one of
69.BR PRIO_PROCESS ,
70.BR PRIO_PGRP ,
71or
72.BR PRIO_USER ,
c13182ef 73and
fea681da 74.I who
c13182ef 75is interpreted relative to
fea681da
MK
76.I which
77(a process identifier for
78.BR PRIO_PROCESS ,
79process group
80identifier for
81.BR PRIO_PGRP ,
82and a user ID for
83.BR PRIO_USER ).
84A zero value for
85.I who
86denotes (respectively) the calling process, the process group of the
87calling process, or the real user ID of the calling process.
88.I Prio
ee6573b9 89is a value in the range \-20 to 19 (but see the Notes below).
fea681da
MK
90The default priority is 0;
91lower priorities cause more favorable scheduling.
92
93The
e511ffb6 94.BR getpriority ()
fea681da 95call returns the highest priority (lowest numerical value)
c13182ef
MK
96enjoyed by any of the specified processes.
97The
e511ffb6 98.BR setpriority ()
fea681da 99call sets the priorities of all of the specified processes
c13182ef
MK
100to the specified value.
101Only the superuser may lower priorities.
fea681da
MK
102.SH "RETURN VALUE"
103Since
e511ffb6 104.BR getpriority ()
fea681da
MK
105can legitimately return the value \-1, it is necessary
106to clear the external variable
107.I errno
108prior to the
109call, then check it afterwards to determine
110if a \-1 is an error or a legitimate value.
111The
e511ffb6 112.BR setpriority ()
fea681da
MK
113call returns 0 if there is no error, or
114\-1 if there is.
115.SH ERRORS
116.TP
117.B EINVAL
118.I which
119was not one of
120.BR PRIO_PROCESS ,
121.BR PRIO_PGRP ,
122or
123.BR PRIO_USER .
124.TP
125.B ESRCH
c13182ef 126No process was located using the
fea681da
MK
127.I which
128and
129.I who
130values specified.
131.PP
132In addition to the errors indicated above,
e511ffb6 133.BR setpriority ()
fea681da
MK
134may fail if:
135.TP
136.B EPERM
137A process was located, but its effective user ID did not match
138either the effective or the real user ID of the caller,
c13182ef 139and was not privileged (on Linux: did not have the
fea681da 140.B CAP_SYS_NICE
d818502d 141capability).
614f40af 142But see NOTES below.
fea681da
MK
143.TP
144.B EACCES
d818502d
MK
145The caller attempted to lower a process priority, but did not
146have the required privilege (on Linux: did not have the
147.B CAP_SYS_NICE
148capability).
23b1b9bc 149Since Linux 2.6.12, this error only occurs if the caller attempts
c13182ef 150to set a process priority outside the range of the
23b1b9bc 151.B RLIMIT_NICE
614f40af 152soft resource limit of the target process; see
23b1b9bc
MK
153.BR getrlimit (2)
154for details.
a1d5f77c
MK
155.SH "CONFORMING TO"
156SVr4, 4.4BSD (these function calls first appeared in 4.2BSD),
157POSIX.1-2001.
fea681da 158.SH NOTES
2cab31c6
MK
159A child created by
160.BR fork (2)
161inherits its parent's nice value.
c13182ef
MK
162The nice value is preserved across
163.BR execve (2).
2cab31c6 164
fea681da 165The details on the condition for EPERM depend on the system.
97c1eac8 166The above description is what POSIX.1-2001 says, and seems to be followed on
80b50848 167all System V-like systems.
c13182ef 168Linux kernels before 2.6.12 required the real or
614f40af 169effective user ID of the caller to match
fea681da 170the real user of the process \fIwho\fP (instead of its effective user ID).
614f40af 171Linux 2.6.12 and later require
fea681da
MK
172the effective user ID of the caller to match
173the real or effective user ID of the process \fIwho\fP.
614f40af 174All BSD-like systems (SunOS 4.1.3, Ultrix 4.2,
c13182ef 1754.3BSD, FreeBSD 4.3, OpenBSD-2.5, ...) behave in the same
614f40af 176manner as Linux >= 2.6.12.
fea681da
MK
177.LP
178The actual priority range varies between kernel versions.
d818502d 179Linux before 1.3.36 had \-infinity..15.
4c111639 180Since kernel 1.3.43 Linux has the range \-20..19.
d818502d
MK
181Within the kernel, nice values are actually represented
182using the corresponding range 40..1
183(since negative numbers are error codes) and these are the values
184employed by the
e511ffb6 185.BR setpriority ()
d818502d 186and
e511ffb6 187.BR getpriority ()
d818502d
MK
188system calls.
189The glibc wrapper functions for these system calls handle the
190translations between the user-land and kernel representations
191of the nice value according to the formula
192.IR "unice\ =\ 20\ \-\ knice" .
fea681da 193.LP
7f185ad2
MK
194On some systems, the range of nice values is \-20..20.
195.LP
fea681da
MK
196Including
197.I <sys/time.h>
198is not required these days, but increases portability.
199(Indeed,
200.I <sys/resource.h>
201defines the
202.I rusage
203structure with fields of type
204.I struct timeval
205defined in
206.IR <sys/time.h> .)
fea681da
MK
207.SH "SEE ALSO"
208.BR nice (1),
209.BR fork (2),
210.BR capabilities (7),
211.BR renice (8)