OSDN Git Service

(split) LDP man-pages の original/ を v3.25 に更新。
[linuxjm/LDP_man-pages.git] / original / man2 / getpriority.2
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>
37 .\" Modified 2001-10-21 by Michael Kerrisk <mtk.manpages@gmail.com>
38 .\"    Corrected statement under EPERM to clarify privileges required
39 .\" Modified 2002-06-21 by Michael Kerrisk <mtk.manpages@gmail.com>
40 .\"    Clarified meaning of 0 value for 'who' argument
41 .\" Modified 2004-05-27 by Michael Kerrisk <mtk.manpages@gmail.com>
42 .\"
43 .\" FIXME Oct 2008: Denys Vlasenko is working on a PRIO_THREAD feature that
44 .\" is likely to get included in mainline; this will need to be documented.
45 .\"
46 .TH GETPRIORITY 2 2008-05-29 "Linux" "Linux Programmer's Manual"
47 .SH NAME
48 getpriority, setpriority \- get/set program scheduling priority
49 .SH SYNOPSIS
50 .B #include <sys/time.h>
51 .br
52 .B #include <sys/resource.h>
53 .sp
54 .BI "int getpriority(int " which ", int " who );
55 .br
56 .BI "int setpriority(int " which ", int " who ", int " prio );
57 .SH DESCRIPTION
58 The scheduling priority of the process, process group, or user, as
59 indicated by
60 .I which
61 and
62 .I who
63 is obtained with the
64 .BR getpriority ()
65 call and set with the
66 .BR setpriority ()
67 call.
68
69 The value
70 .I which
71 is one of
72 .BR PRIO_PROCESS ,
73 .BR PRIO_PGRP ,
74 or
75 .BR PRIO_USER ,
76 and
77 .I who
78 is interpreted relative to
79 .I which
80 (a process identifier for
81 .BR PRIO_PROCESS ,
82 process group
83 identifier for
84 .BR PRIO_PGRP ,
85 and a user ID for
86 .BR PRIO_USER ).
87 A zero value for
88 .I who
89 denotes (respectively) the calling process, the process group of the
90 calling process, or the real user ID of the calling process.
91 .I Prio
92 is a value in the range \-20 to 19 (but see the Notes below).
93 The default priority is 0;
94 lower priorities cause more favorable scheduling.
95
96 The
97 .BR getpriority ()
98 call returns the highest priority (lowest numerical value)
99 enjoyed by any of the specified processes.
100 The
101 .BR setpriority ()
102 call sets the priorities of all of the specified processes
103 to the specified value.
104 Only the superuser may lower priorities.
105 .SH "RETURN VALUE"
106 Since
107 .BR getpriority ()
108 can legitimately return the value \-1, it is necessary
109 to clear the external variable
110 .I errno
111 prior to the
112 call, then check it afterwards to determine
113 if \-1 is an error or a legitimate value.
114 The
115 .BR setpriority ()
116 call returns 0 if there is no error, or
117 \-1 if there is.
118 .SH ERRORS
119 .TP
120 .B EINVAL
121 .I which
122 was not one of
123 .BR PRIO_PROCESS ,
124 .BR PRIO_PGRP ,
125 or
126 .BR PRIO_USER .
127 .TP
128 .B ESRCH
129 No process was located using the
130 .I which
131 and
132 .I who
133 values specified.
134 .PP
135 In addition to the errors indicated above,
136 .BR setpriority ()
137 may fail if:
138 .TP
139 .B EACCES
140 The caller attempted to lower a process priority, but did not
141 have the required privilege (on Linux: did not have the
142 .B CAP_SYS_NICE
143 capability).
144 Since Linux 2.6.12, this error only occurs if the caller attempts
145 to set a process priority outside the range of the
146 .B RLIMIT_NICE
147 soft resource limit of the target process; see
148 .BR getrlimit (2)
149 for details.
150 .TP
151 .B EPERM
152 A process was located, but its effective user ID did not match
153 either the effective or the real user ID of the caller,
154 and was not privileged (on Linux: did not have the
155 .B CAP_SYS_NICE
156 capability).
157 But see NOTES below.
158 .SH "CONFORMING TO"
159 SVr4, 4.4BSD (these function calls first appeared in 4.2BSD),
160 POSIX.1-2001.
161 .SH NOTES
162 A child created by
163 .BR fork (2)
164 inherits its parent's nice value.
165 The nice value is preserved across
166 .BR execve (2).
167
168 The degree to which their relative nice value affects the scheduling of
169 processes varies across Unix systems, and,
170 on Linux, across kernel versions.
171 Starting with kernel 2.6.23, Linux adopted an algorithm that causes
172 relative differences in nice values to have a much stronger effect.
173 This causes very low nice values (+19) to truly provide little CPU
174 to a process whenever there is any other
175 higher priority load on the system,
176 and makes high nice values (\-20) deliver most of the CPU to applications
177 that require it (e.g., some audio applications).
178
179 The details on the condition for
180 .B EPERM
181 depend on the system.
182 The above description is what POSIX.1-2001 says, and seems to be followed on
183 all System V-like systems.
184 Linux kernels before 2.6.12 required the real or
185 effective user ID of the caller to match
186 the real user of the process \fIwho\fP (instead of its effective user ID).
187 Linux 2.6.12 and later require
188 the effective user ID of the caller to match
189 the real or effective user ID of the process \fIwho\fP.
190 All BSD-like systems (SunOS 4.1.3, Ultrix 4.2,
191 4.3BSD, FreeBSD 4.3, OpenBSD-2.5, ...) behave in the same
192 manner as Linux 2.6.12 and later.
193 .LP
194 The actual priority range varies between kernel versions.
195 Linux before 1.3.36 had \-infinity..15.
196 Since kernel 1.3.43 Linux has the range \-20..19.
197 Within the kernel, nice values are actually represented
198 using the corresponding range 40..1
199 (since negative numbers are error codes) and these are the values
200 employed by the
201 .BR setpriority ()
202 and
203 .BR getpriority ()
204 system calls.
205 The glibc wrapper functions for these system calls handle the
206 translations between the user-land and kernel representations
207 of the nice value according to the formula
208 .IR "unice\ =\ 20\ \-\ knice" .
209 .LP
210 On some systems, the range of nice values is \-20..20.
211 .LP
212 Including
213 .I <sys/time.h>
214 is not required these days, but increases portability.
215 (Indeed,
216 .I <sys/resource.h>
217 defines the
218 .I rusage
219 structure with fields of type
220 .I struct timeval
221 defined in
222 .IR <sys/time.h> .)
223 .SH "SEE ALSO"
224 .BR nice (1),
225 .BR fork (2),
226 .BR capabilities (7),
227 .BR renice (1)
228 .sp
229 .I Documentation/scheduler/sched-nice-design.txt
230 in the kernel source tree (since Linux 2.6.23).