1 .\" Copyright (c) 1980, 1991 The Regents of the University of California.
2 .\" All rights reserved.
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
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.
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
32 .\" @(#)getpriority.2 6.9 (Berkeley) 3/10/91
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>
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.
46 .\" Japanese Version Copyright (c) 1997 HANATAKA Shinya
47 .\" all rights reserved.
48 .\" Translated 1997-02-22, HANATAKA Shinya <hanataka@abyss.rim.or.jp>
49 .\" Modified 2001-08-17, HANATAKA Shinya <hanataka@abyss.rim.or.jp>
50 .\" Modified 2001-10-18, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
51 .\" Updated 2001-12-13, Kentaro Shirakata <argrath@ub32.org>
52 .\" Updated 2002-10-16, Kentaro Shirakata <argrath@ub32.org>
53 .\" Updated 2005-02-24, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
54 .\" Updated 2005-10-07, Akihiro MOTOKI
55 .\" Updated 2008-08-04, Akihiro MOTOKI, LDP v3.05
57 .\"WORD: scheduling ¥¹¥±¥¸¥å¡¼¥ê¥ó¥°
58 .\"WORD: piority Í¥ÀèÅÙ
61 .\"WORD: process ¥×¥í¥»¥¹
62 .\"WORD: user ¥æ¡¼¥¶¡¼
63 .\"WORD: super user ¥¹¡¼¥Ñ¡¼¡¦¥æ¡¼¥¶¡¼
64 .\"WORD: effective user-ID ¼Â¸úUID
65 .\"WORD: real user-ID ¼ÂUID
67 .TH GETPRIORITY 2 2008-05-29 "Linux" "Linux Programmer's Manual"
70 .\"O getpriority, setpriority \- get/set program scheduling priority
71 getpriority, setpriority \- ¥×¥í¥°¥é¥à¤Î¥¹¥±¥¸¥å¡¼¥ê¥ó¥°¤ÎÍ¥ÀèÅÙ¤ò¼èÆÀ/ÀßÄꤹ¤ë
74 .B #include <sys/time.h>
76 .B #include <sys/resource.h>
78 .BI "int getpriority(int " which ", int " who );
80 .BI "int setpriority(int " which ", int " who ", int " prio );
83 .\"O The scheduling priority of the process, process group, or user, as
88 .\"O is obtained with the
89 .\"O .BR getpriority ()
90 .\"O call and set with the
91 .\"O .BR setpriority ()
101 ¤Ç»ØÄꤵ¤ì¤¿¥×¥í¥»¥¹¡¢¥×¥í¥»¥¹¡¦¥°¥ë¡¼¥×¡¢¥æ¡¼¥¶¡¼¤Î
102 ¥¹¥±¥¸¥å¡¼¥ê¥ó¥°Í¥ÀèÅÙ (scheduling priority) ¤Î
103 ¼èÆÀ¤äÀßÄê¤ò¤½¤ì¤¾¤ì¹Ô¤¦¡£
108 .\"O .BR PRIO_PROCESS ,
114 .\"O is interpreted relative to
116 .\"O (a process identifier for
117 .\"O .BR PRIO_PROCESS ,
121 .\"O and a user ID for
122 .\"O .BR PRIO_USER ).
136 ¤À¤È¥×¥í¥»¥¹¡¦¥°¥ë¡¼¥×¼±Ê̻ҡ¢
138 ¤À¤È UID (¥æ¡¼¥¶ID) ¤È²ò¼á¤µ¤ì¤ë)¡£
139 .\"O A zero value for
141 .\"O denotes (respectively) the calling process, the process group of the
142 .\"O calling process, or the real user ID of the calling process.
144 ¤¬¥¼¥í¤Ê¤é¤Ð¡¢(¤½¤ì¤¾¤ì)¸Æ¤Ó½Ð¤·¤¿¥×¥í¥»¥¹¡¢
145 ¸Æ¤Ó½Ð¤·¤¿¥×¥í¥»¥¹¤Î¥×¥í¥»¥¹¡¦¥°¥ë¡¼¥×¡¢
146 ¸Æ¤Ó½Ð¤·¤¿¥×¥í¥»¥¹¤Î¼ÂUID ¤ò°ÕÌ£¤¹¤ë¡£
148 .\"O is a value in the range \-20 to 19 (but see the Notes below).
149 .\"O The default priority is 0;
150 .\"O lower priorities cause more favorable scheduling.
152 ¤Ï \-20 ¤«¤é 19 ¤ÎÈϰϤÎÃÍ¤Ç (⤷°Ê²¼¤ÎÃí°Õ¤Î¹à¤ò»²¾È¤Î¤³¤È)¡¢
153 ¥Ç¥Õ¥©¥ë¥È¤ÎÍ¥ÀèÅÙ¤Ï 0 ¤Ç¤¢¤ë;
154 ¾®¤µ¤Ê¿ô»ú¤Û¤É¡¢ÍÍø¤Ê¥¹¥±¥¸¥å¡¼¥ê¥ó¥°¤È¤Ê¤ë¡£
157 .\"O .BR getpriority ()
158 .\"O call returns the highest priority (lowest numerical value)
159 .\"O enjoyed by any of the specified processes.
161 .\"O .BR setpriority ()
162 .\"O call sets the priorities of all of the specified processes
163 .\"O to the specified value.
164 .\"O Only the superuser may lower priorities.
166 ¥³¡¼¥ë¤Ï»ØÄꤷ¤¿¥×¥í¥»¥¹¤ÎÃæ¤ÎºÇ¤â¹â¤¤Í¥ÀèÅÙ (¿ôÃÍŪ¤Ë¤ÏºÇ¾®¤ÎÃÍ) ¤òÊÖ¤¹¡£
168 ¥³¡¼¥ë¤Ï»ØÄꤷ¤¿¥×¥í¥»¥¹Á´¤Æ¤ÎÍ¥ÀèÅÙ¤ò»ØÄꤷ¤¿ÃͤËÀßÄꤹ¤ë¡£
169 Í¥ÀèÅÙ¤òº£¤è¤ê¾®¤µ¤¤ÃͤËÀßÄê¤Ç¤¤ë¤Î¤Ï¥¹¡¼¥Ñ¡¼¡¦¥æ¡¼¥¶¡¼¤À¤±¤Ç¤¢¤ë¡£
170 .\"O .SH "RETURN VALUE"
173 .\"O .BR getpriority ()
174 .\"O can legitimately return the value \-1, it is necessary
175 .\"O to clear the external variable
178 .\"O call, then check it afterwards to determine
179 .\"O if \-1 is an error or a legitimate value.
181 .\"O .BR setpriority ()
182 .\"O call returns 0 if there is no error, or
183 .\"O \-1 if there is.
185 ¤ÏÀ®¸ù¤·¤¿¾ì¹ç¤Ë¤â \-1 ¤ÎÃͤòÊÖ¤¹²ÄǽÀ¤¬¤¢¤ë¤Î¤Ç¡¢
186 ¸Æ¤Ó½Ð¤·¤ÎÁ°¤Ë³°ÉôÊÑ¿ô¤Î
188 ¤ò¥¯¥ê¥¢¤·¡¢¸Æ¤Ó½Ð¤·¤Î¸å¤ËÊÖ¤êÃͤΠ\-1 ¤¬ÀµÅö¤ÊÃͤ«
189 ¥¨¥é¡¼¤«¤òȽÊ̤¹¤ëɬÍפ¬¤¢¤ë¡£
191 ¥³¡¼¥ë¤Ï¥¨¥é¡¼¤¬¤Ê¤±¤ì¤Ð 0 ¤òÊÖ¤·¡¢¥¨¥é¡¼¤¬¤¢¤ì¤Ð \-1 ¤òÊÖ¤¹¡£
199 .\"O .BR PRIO_PROCESS ,
211 .\"O No process was located using the
215 .\"O values specified.
219 ¤Ç»ØÄꤵ¤ì¤¿¥×¥í¥»¥¹¤¬Â¸ºß¤·¤Ê¤¤¡£
221 .\"O In addition to the errors indicated above,
222 .\"O .BR setpriority ()
226 ¤Ç¤Ï°Ê²¼¤Î¥¨¥é¡¼¤¬¤¢¤ë:
229 .\"O The caller attempted to lower a process priority, but did not
230 .\"O have the required privilege (on Linux: did not have the
233 .\"O Since Linux 2.6.12, this error only occurs if the caller attempts
234 .\"O to set a process priority outside the range of the
236 .\"O soft resource limit of the target process; see
237 .\"O .BR getrlimit (2)
239 ¸Æ¤Ó½Ð¤·¸µ¤¬¥×¥í¥»¥¹¤ÎÍ¥ÀèÅÙ¤ò²¼¤²¤è¤¦¤È¤·¤¿¤¬¡¢É¬ÍפÊÆø¢¤ò
240 »ý¤Ã¤Æ¤¤¤Ê¤«¤Ã¤¿ (Linux ¤Î¾ì¹ç¡¢
242 ¥±¡¼¥Ñ¥Ó¥ê¥Æ¥£¤¬¤Ê¤«¤Ã¤¿)¡£
243 Linux 2.6.12 °Ê¹ß¤Ç¤Ï¡¢¸Æ¤Ó½Ð¤·¸µ¤¬¡¢¤¢¤ë¥×¥í¥»¥¹¤ÎÍ¥ÀèÅÙ¤ò¡¢
244 Êѹ¹ÂÐ¾Ý¤Î¥×¥í¥»¥¹¤Î¥ê¥½¡¼¥¹
246 ¤Î¥½¥Õ¥È¡¦¥ê¥ß¥Ã¥È¤ÎÈϰϳ°¤ËÀßÄꤷ¤è¤¦¤È¤·¤¿¾ì¹ç¤Ë¤Î¤ß¡¢
247 ¤³¤Î¥¨¥é¡¼¤¬È¯À¸¤¹¤ë¡£¾ÜºÙ¤Ï
252 .\"O A process was located, but its effective user ID did not match
253 .\"O either the effective or the real user ID of the caller,
254 .\"O and was not privileged (on Linux: did not have the
257 .\"O But see NOTES below.
258 ¥×¥í¥»¥¹¤Ï¸«¤Ä¤«¤Ã¤¿¤¬¡¢¤½¤Î¥×¥í¥»¥¹¤Î¼Â¸ú (effective) UID ¤¬
259 ¸Æ¤Ó½Ð¤·¸µ¤Î¼Â¸úUID ¤Ë¤â¼Â (real) UID ¤Ë¤â°ìÃפ»¤º¡¢
260 ¸Æ¤Ó½Ð¤·¸µ¤¬Æø¢¤â»ý¤Ã¤Æ¤¤¤Ê¤«¤Ã¤¿ (Linux ¤Î¾ì¹ç¡¢
262 ¥±¡¼¥Ñ¥Ó¥ê¥Æ¥£¤¬¤Ê¤«¤Ã¤¿)¡£
263 °Ê²¼¤Î¡ÖÃí°Õ¡×¤â»²¾È¤Î¤³¤È¡£
264 .\"O .SH "CONFORMING TO"
266 .\"O SVr4, 4.4BSD (these function calls first appeared in 4.2BSD),
268 SVr4, 4.4BSD (¤³¤ì¤é¤Î´Ø¿ô¤Ï 4.2BSD ¤ÇºÇ½é¤ËÅо줷¤¿),
272 .\"O A child created by
274 .\"O inherits its parent's nice value.
275 .\"O The nice value is preserved across
278 ¤ÇºîÀ®¤µ¤ì¤¿»Ò¥×¥í¥»¥¹¤Ï¡¢
279 ¿Æ¥×¥í¥»¥¹¤Î nice Ãͤò·Ñ¾µ¤¹¤ë¡£
281 ¤ÎÁ°¸å¤Ç nice ÃͤÏÊݸ¤µ¤ì¤ë¡£
283 .\"O The degree to which their relative nice value affects the scheduling of
284 .\"O processes varies across Unix systems, and,
285 .\"O on Linux, across kernel versions.
286 .\"O Starting with kernel 2.6.23, Linux adopted an algorithm that causes
287 .\"O relative differences in nice values to have a much stronger effect.
288 .\"O This causes very low nice values (+19) to truly provide little CPU
289 .\"O to a process whenever there is any other
290 .\"O higher priority load on the system,
291 .\"O and makes high nice values (\-20) deliver most of the CPU to applications
292 .\"O that require it (e.g., some audio applications).
293 ÁêÂÐŪ¤Ê nice Ãͤΰ㤤¤¬¥×¥í¥»¥¹´Ö¤Î¥¹¥±¥¸¥å¡¼¥ê¥ó¥°¤Ë¤É¤ÎÄøÅٱƶÁ¤òÍ¿¤¨¤ë¤«
294 ¤Ï¡¢Unix ¥·¥¹¥Æ¥à´Ö¤Ç°Û¤Ê¤ê¡¢Linux ¤Ç¤Ï¥«¡¼¥Í¥ë¥Ð¡¼¥¸¥ç¥ó¤Ë¤è¤ê°Û¤Ê¤ë¡£
295 Linux ¤Ï¡¢¥«¡¼¥Í¥ë 2.6.23 °Ê¹ß¤Ç¡¢nice ÃͤÎÁêÂÐŪ¤Ê°ã¤¤¤¬¡¢Èó¾ï¤Ë¶¯¤¤±Æ¶Á¤ò
296 Í¿¤¨¤ë¥¢¥ë¥´¥ê¥º¥à¤òºÎÍѤ·¤¿¡£¤³¤Î¥¢¥ë¥´¥ê¥º¥à¤Ç¤Ï¡¢
297 ¾¤ËÍ¥ÀèÅ٤ι⤤¤â¤Î¤¬¥·¥¹¥Æ¥à¤Ë¸ºß¤¹¤ë»þ¤Ë¤Ï¡¢
298 Èó¾ï¤ËÄ㤤 nice ÃÍ (+19) ¤Ç¤Ï¥×¥í¥»¥¹¤ËËÜÅö¤Ë¤Û¤È¤ó¤É CPU ¤¬³ä¤êÅö¤Æ¤é¤ì¤Ê¤¤¡£
299 ¤Þ¤¿¡¢¹â¤¤ nice ÃÍ (\-20) ¤Ç¤Ï CPU ¤òɬÍפȤ¹¤ë¥¢¥×¥ê¥±¡¼¥·¥ç¥ó (Î㤨¤Ð
300 ¥ª¡¼¥Ç¥£¥ª¡¦¥¢¥×¥ê¥±¡¼¥·¥ç¥ó) ¤Ë CPU ¤Î¤Û¤È¤ó¤É¤¬³ä¤êÅö¤Æ¤é¤ì¤ë¡£
302 .\"O The details on the condition for
304 .\"O depend on the system.
306 ¤¬È¯À¸¤¹¤ë¾ò·ï¤Î¾ÜºÙ¤Ï¥·¥¹¥Æ¥à¤Ë°Í¸¤¹¤ë¡£
307 .\"O The above description is what POSIX.1-2001 says, and seems to be followed on
308 .\"O all System V-like systems.
309 ¾åµ¤ÎÀâÌÀ¤Ï POSIX.1-2001 ¤Î¤â¤Î¤Ç¤¢¤ê¡¢Á´¤Æ¤Î System V É÷¥·¥¹¥Æ¥à¤Ï
310 ¤³¤ì¤Ë½¾¤Ã¤Æ¤¤¤ë¤è¤¦¤Ç¤¢¤ë¡£
311 .\"O Linux kernels before 2.6.12 required the real or
312 .\"O effective user ID of the caller to match
313 .\"O the real user of the process \fIwho\fP (instead of its effective user ID).
314 2.6.12 ¤è¤êÁ°¤Î Linux ¥«¡¼¥Í¥ë¤Ç¤Ï¡¢¸Æ¤Ó½Ð¤·¸µ¤Î¼Â UID ¤Þ¤¿¤Ï
315 ¼Â¸ú UID ¤¬¥×¥í¥»¥¹ \fIwho\fP ¤Î (¼Â¸ú UID ¤Ç¤Ê¤¯)
316 ¼Â UID ¤Ë°ìÃפ¹¤ëɬÍפ¬¤¢¤ë¡£
317 .\"O Linux 2.6.12 and later require
318 .\"O the effective user ID of the caller to match
319 .\"O the real or effective user ID of the process \fIwho\fP.
320 .\"O All BSD-like systems (SunOS 4.1.3, Ultrix 4.2,
321 .\"O 4.3BSD, FreeBSD 4.3, OpenBSD-2.5, ...) behave in the same
322 .\"O manner as Linux 2.6.12 and later.
323 Linux 2.6.12 °Ê¹ß¤Ç¤Ï¡¢¸Æ¤Ó½Ð¤·¸µ¤Î¼Â¹Ô UID ¤¬¥×¥í¥»¥¹ \fIwho\fP
324 ¤Î¼Â UID ¤«¼Â¸ú UID ¤Î¤¤¤º¤ì¤«¤È°ìÃפ¹¤ëɬÍפ¬¤¢¤ë¡£
325 Á´¤Æ¤Î BSD É÷¥·¥¹¥Æ¥à (SunOS 4.1.3, Ultrix 4.2,
326 4.3BSD, FreeBSD 4.3, OpenBSD-2.5Åù) ¤Ï¡¢
327 Linux 2.6.12 °Ê¹ß¤ÈƱ¤¸Æ°ºî¤ò¤¹¤ë¡£
329 .\"O The actual priority range varies between kernel versions.
330 .\"O Linux before 1.3.36 had \-infinity..15.
331 .\"O Since kernel 1.3.43 Linux has the range \-20..19.
332 .\"O Within the kernel, nice values are actually represented
333 .\"O using the corresponding range 40..1
334 .\"O (since negative numbers are error codes) and these are the values
336 .\"O .BR setpriority ()
338 .\"O .BR getpriority ()
340 .\"O The glibc wrapper functions for these system calls handle the
341 .\"O translations between the user-land and kernel representations
342 .\"O of the nice value according to the formula
343 .\"O .IR "unice\ =\ 20\ \-\ knice" .
344 ¼ÂºÝ¤ÎÍ¥ÀèÅÙ¤ÎÃͤÎÈϰϤϥ«¡¼¥Í¥ë¤Î¥Ð¡¼¥¸¥ç¥ó¤Ë¤è¤Ã¤Æ°Û¤Ê¤ë¡£
345 1.3.36 ¤è¤êÁ°¤Î Linux ¤Ç¤Ï¡¢Í¥ÀèÅÙ¤ÎÈϰϤÏÉé¤Î̵¸ÂÂç ¡Á 15 ¤Ç¤¢¤ë¡£
346 1.3.43 °Ê¹ß¤Î Linux ¤Ç¤Ï¡¢Í¥ÀèÅÙ¤ÎÈÏ°Ï¤Ï \-20 ¡Á 19 ¤Ç¤¢¤ë¡£
347 ¥«¡¼¥Í¥ëÆâÉô¤Ç¤Ï¡¢nice ÃÍ¤Ï¼ÂºÝ¤Ë¤Ï 40 ¡Á 1 ¤ÎÈϰϤò»È¤Ã¤Æ
348 ɽ¸½¤µ¤ì¤Æ¤ª¤ê (Éé¤ÎÃͤϥ¨¥é¡¼¥³¡¼¥É¤È¤Ê¤ë¤¿¤á)¡¢¤³¤Á¤é¤ÎÃͤ¬
354 glibc ¤Î¤³¤ì¤é¤Î¥·¥¹¥Æ¥à¥³¡¼¥ë¤Î¥é¥Ã¥Ñ¡¼´Ø¿ô¤Ë¤ª¤¤¤Æ¡¢nice ÃͤÎ
355 ¥æ¡¼¥¶Îΰè (user-land) ¤È¥«¡¼¥Í¥ëɽ¸½¤Î´Ö¤ÎÊÑ´¹¤¬¹Ô¤ï¤ì¤ë¡£
357 .I "unice\ =\ 20\ \-\ knice"
359 .\"O On some systems, the range of nice values is \-20..20.
360 ¤¤¤¯¤Ä¤«¤Î¥·¥¹¥Æ¥à¤Ç¤Ï¡¢nice ÃͤÎÈÏ°Ï¤Ï \20 ¡Á 20 ¤Ç¤¢¤ë¡£
364 .\"O is not required these days, but increases portability.
366 .\"O .I <sys/resource.h>
369 .\"O structure with fields of type
370 .\"O .I struct timeval
372 .\"O .IR <sys/time.h> .)
375 ¤ò¥¤¥ó¥¯¥ë¡¼¥É¤¹¤ëɬÍפϤʤ¤¤¬¡¢¥¤¥ó¥¯¥ë¡¼¥É¤¹¤ì¤Ð°Ü¿¢À¤ò¹â¤á¤ë¤³¤È¤¬¤Ç¤¤ë
380 ¹½Â¤ÂΤ¬ÄêµÁ¤µ¤ì¤Æ¤¤¤ë¤¬¡¢¤½¤Î¥Õ¥£¡¼¥ë¥É¤Ç»ÈÍѤµ¤ì¤Æ¤¤¤ë
389 .BR capabilities (7),
392 .\"O .I Documentation/scheduler/sched-nice-design.txt
393 .\"O in the kernel source tree (since Linux 2.6.23).
394 (Linux 2.6.23 °Ê¹ß¤Î) ¥«¡¼¥Í¥ë¤Î¥½¡¼¥¹¥Ä¥ê¡¼Æâ¤Î
395 .I Documentation/scheduler/sched-nice-design.txt