.\" Copyright (c) 1980, 1991 The Regents of the University of California. .\" All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" 3. All advertising materials mentioning features or use of this software .\" must display the following acknowledgement: .\" This product includes software developed by the University of .\" California, Berkeley and its contributors. .\" 4. Neither the name of the University nor the names of its contributors .\" may be used to endorse or promote products derived from this software .\" without specific prior written permission. .\" .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" .\" @(#)getpriority.2 6.9 (Berkeley) 3/10/91 .\" .\" Modified 1993-07-24 by Rik Faith .\" Modified 1996-07-01 by Andries Brouwer .\" Modified 1996-11-06 by Eric S. Raymond .\" Modified 2001-10-21 by Michael Kerrisk .\" Corrected statement under EPERM to clarify privileges required .\" Modified 2002-06-21 by Michael Kerrisk .\" Clarified meaning of 0 value for 'who' argument .\" Modified 2004-05-27 by Michael Kerrisk .\" .\" FIXME Oct 2008: Denys Vlasenko is working on a PRIO_THREAD feature that .\" is likely to get included in mainline; this will need to be documented. .\" .\" Japanese Version Copyright (c) 1997 HANATAKA Shinya .\" all rights reserved. .\" Translated 1997-02-22, HANATAKA Shinya .\" Modified 2001-08-17, HANATAKA Shinya .\" Modified 2001-10-18, Akihiro MOTOKI .\" Updated 2001-12-13, Kentaro Shirakata .\" Updated 2002-10-16, Kentaro Shirakata .\" Updated 2005-02-24, Akihiro MOTOKI .\" Updated 2005-10-07, Akihiro MOTOKI .\" Updated 2008-08-04, Akihiro MOTOKI, LDP v3.05 .\" .\"WORD: scheduling スケジューリング .\"WORD: piority 優先度 .\"WORD: call コール .\"WORD: user-ID UID .\"WORD: process プロセス .\"WORD: user ユーザー .\"WORD: super user スーパー・ユーザー .\"WORD: effective user-ID 実効UID .\"WORD: real user-ID 実UID .\" .TH GETPRIORITY 2 2008-05-29 "Linux" "Linux Programmer's Manual" .\"O .SH NAME .SH 名前 .\"O getpriority, setpriority \- get/set program scheduling priority getpriority, setpriority \- プログラムのスケジューリングの優先度を取得/設定する .\"O .SH SYNOPSIS .SH 書式 .B #include .br .B #include .sp .BI "int getpriority(int " which ", int " who ); .br .BI "int setpriority(int " which ", int " who ", int " prio ); .\"O .SH DESCRIPTION .SH 説明 .\"O The scheduling priority of the process, process group, or user, as .\"O indicated by .\"O .I which .\"O and .\"O .I who .\"O is obtained with the .\"O .BR getpriority () .\"O call and set with the .\"O .BR setpriority () .\"O call. システムコール .BR getpriority () や .BR setpriority () は、 .I which と .I who で指定されたプロセス、プロセス・グループ、ユーザーの スケジューリング優先度 (scheduling priority) の 取得や設定をそれぞれ行う。 .\"O The value .\"O .I which .\"O is one of .\"O .BR PRIO_PROCESS , .\"O .BR PRIO_PGRP , .\"O or .\"O .BR PRIO_USER , .\"O and .\"O .I who .\"O is interpreted relative to .\"O .I which .\"O (a process identifier for .\"O .BR PRIO_PROCESS , .\"O process group .\"O identifier for .\"O .BR PRIO_PGRP , .\"O and a user ID for .\"O .BR PRIO_USER ). .I which の値は .BR PRIO_PROCESS , .BR PRIO_PGRP , .BR PRIO_USER , のどれか一つで、 .I who は .I which に応じて解釈される .RB ( PRIO_PROCESS だとプロセス識別子、 .B PRIO_PGRP だとプロセス・グループ識別子、 .B PRIO_USER だと UID (ユーザID) と解釈される)。 .\"O A zero value for .\"O .I who .\"O denotes (respectively) the calling process, the process group of the .\"O calling process, or the real user ID of the calling process. .I who がゼロならば、(それぞれ)呼び出したプロセス、 呼び出したプロセスのプロセス・グループ、 呼び出したプロセスの実UID を意味する。 .\"O .I Prio .\"O is a value in the range \-20 to 19 (but see the Notes below). .\"O The default priority is 0; .\"O lower priorities cause more favorable scheduling. .I prio は \-20 から 19 の範囲の値で (但し以下の注意の項を参照のこと)、 デフォルトの優先度は 0 である; 小さな数字ほど、有利なスケジューリングとなる。 .\"O The .\"O .BR getpriority () .\"O call returns the highest priority (lowest numerical value) .\"O enjoyed by any of the specified processes. .\"O The .\"O .BR setpriority () .\"O call sets the priorities of all of the specified processes .\"O to the specified value. .\"O Only the superuser may lower priorities. .BR getpriority () コールは指定したプロセスの中の最も高い優先度 (数値的には最小の値) を返す。 .BR setpriority () コールは指定したプロセス全ての優先度を指定した値に設定する。 優先度を今より小さい値に設定できるのはスーパー・ユーザーだけである。 .\"O .SH "RETURN VALUE" .SH 返り値 .\"O Since .\"O .BR getpriority () .\"O can legitimately return the value \-1, it is necessary .\"O to clear the external variable .\"O .I errno .\"O prior to the .\"O call, then check it afterward to determine .\"O if \-1 is an error or a legitimate value. .\"O The .\"O .BR setpriority () .\"O call returns 0 if there is no error, or .\"O \-1 if there is. .BR getpriority () は成功した場合にも \-1 の値を返す可能性があるので、 呼び出しの前に外部変数の .I errno をクリアし、呼び出しの後に返り値の \-1 が正当な値か エラーかを判別する必要がある。 .BR setpriority () コールはエラーがなければ 0 を返し、エラーがあれば \-1 を返す。 .\"O .SH ERRORS .SH エラー .TP .B EINVAL .\"O .I which .\"O was not one of .\"O .BR PRIO_PROCESS , .\"O .BR PRIO_PGRP , .\"O or .\"O .BR PRIO_USER . .I which が .BR PRIO_PROCESS , .BR PRIO_PGRP , .B PRIO_USER のいずれでもない。 .TP .B ESRCH .\"O No process was located using the .\"O .I which .\"O and .\"O .I who .\"O values specified. .I which と .I who で指定されたプロセスが存在しない。 .PP .\"O In addition to the errors indicated above, .\"O .BR setpriority () .\"O may fail if: 上記のものに加えて .BR setpriority () では以下のエラーがある: .TP .B EACCES .\"O The caller attempted to lower a process priority, but did not .\"O have the required privilege (on Linux: did not have the .\"O .B CAP_SYS_NICE .\"O capability). .\"O Since Linux 2.6.12, this error only occurs if the caller attempts .\"O to set a process priority outside the range of the .\"O .B RLIMIT_NICE .\"O soft resource limit of the target process; see .\"O .BR getrlimit (2) .\"O for details. 呼び出し元がプロセスの優先度を下げようとしたが、必要な特権を 持っていなかった (Linux の場合、 .B CAP_SYS_NICE ケーパビリティがなかった)。 Linux 2.6.12 以降では、呼び出し元が、あるプロセスの優先度を、 変更対象のプロセスのリソース .B RLIMIT_NICE のソフト・リミットの範囲外に設定しようとした場合にのみ、 このエラーが発生する。詳細は .BR getrlimit (2) を参照。 .TP .B EPERM .\"O A process was located, but its effective user ID did not match .\"O either the effective or the real user ID of the caller, .\"O and was not privileged (on Linux: did not have the .\"O .B CAP_SYS_NICE .\"O capability). .\"O But see NOTES below. プロセスは見つかったが、そのプロセスの実効 (effective) UID が 呼び出し元の実効UID にも実 (real) UID にも一致せず、 呼び出し元が特権も持っていなかった (Linux の場合、 .B CAP_SYS_NICE ケーパビリティがなかった)。 以下の「注意」も参照のこと。 .\"O .SH "CONFORMING TO" .SH 準拠 .\"O SVr4, 4.4BSD (these function calls first appeared in 4.2BSD), .\"O POSIX.1-2001. SVr4, 4.4BSD (これらの関数は 4.2BSD で最初に登場した), POSIX.1-2001. .\"O .SH NOTES .SH 注意 .\"O A child created by .\"O .BR fork (2) .\"O inherits its parent's nice value. .\"O The nice value is preserved across .\"O .BR execve (2). .BR fork (2) で作成された子プロセスは、 親プロセスの nice 値を継承する。 .BR execve (2) の前後で nice 値は保存される。 .\"O The degree to which their relative nice value affects the scheduling of .\"O processes varies across UNIX systems, and, .\"O on Linux, across kernel versions. .\"O Starting with kernel 2.6.23, Linux adopted an algorithm that causes .\"O relative differences in nice values to have a much stronger effect. .\"O This causes very low nice values (+19) to truly provide little CPU .\"O to a process whenever there is any other .\"O higher priority load on the system, .\"O and makes high nice values (\-20) deliver most of the CPU to applications .\"O that require it (e.g., some audio applications). 相対的な nice 値の違いがプロセス間のスケジューリングにどの程度影響を与えるか は、UNIX システム間で異なり、Linux ではカーネルバージョンにより異なる。 Linux は、カーネル 2.6.23 以降で、nice 値の相対的な違いが、非常に強い影響を 与えるアルゴリズムを採用した。このアルゴリズムでは、 他に優先度の高いものがシステムに存在する時には、 非常に低い nice 値 (+19) ではプロセスに本当にほとんど CPU が割り当てられない。 また、高い nice 値 (\-20) では CPU を必要とするアプリケーション (例えば オーディオ・アプリケーション) に CPU のほとんどが割り当てられる。 .\"O The details on the condition for .\"O .B EPERM .\"O depend on the system. .B EPERM が発生する条件の詳細はシステムに依存する。 .\"O The above description is what POSIX.1-2001 says, and seems to be followed on .\"O all System V-like systems. 上記の説明は POSIX.1-2001 のものであり、全ての System V 風システムは これに従っているようである。 .\"O Linux kernels before 2.6.12 required the real or .\"O effective user ID of the caller to match .\"O the real user of the process \fIwho\fP (instead of its effective user ID). 2.6.12 より前の Linux カーネルでは、呼び出し元の実 UID または 実効 UID がプロセス \fIwho\fP の (実効 UID でなく) 実 UID に一致する必要がある。 .\"O Linux 2.6.12 and later require .\"O the effective user ID of the caller to match .\"O the real or effective user ID of the process \fIwho\fP. .\"O All BSD-like systems (SunOS 4.1.3, Ultrix 4.2, .\"O 4.3BSD, FreeBSD 4.3, OpenBSD-2.5, ...) behave in the same .\"O manner as Linux 2.6.12 and later. Linux 2.6.12 以降では、呼び出し元の実行 UID がプロセス \fIwho\fP の実 UID か実効 UID のいずれかと一致する必要がある。 全ての BSD 風システム (SunOS 4.1.3, Ultrix 4.2, 4.3BSD, FreeBSD 4.3, OpenBSD-2.5等) は、 Linux 2.6.12 以降と同じ動作をする。 .LP .\"O The actual priority range varies between kernel versions. .\"O Linux before 1.3.36 had \-infinity..15. .\"O Since kernel 1.3.43 Linux has the range \-20..19. .\"O Within the kernel, nice values are actually represented .\"O using the corresponding range 40..1 .\"O (since negative numbers are error codes) and these are the values .\"O employed by the .\"O .BR setpriority () .\"O and .\"O .BR getpriority () .\"O system calls. .\"O The glibc wrapper functions for these system calls handle the .\"O translations between the user-land and kernel representations .\"O of the nice value according to the formula .\"O .IR "unice\ =\ 20\ \-\ knice" . 実際の優先度の値の範囲はカーネルのバージョンによって異なる。 1.3.36 より前の Linux では、優先度の範囲は負の無限大 〜 15 である。 1.3.43 以降の Linux では、優先度の範囲は \-20 〜 19 である。 カーネル内部では、nice 値は実際には 40 〜 1 の範囲を使って 表現されており (負の値はエラーコードとなるため)、こちらの値が システムコール .BR setpriority () と .BR getpriority () で使用されている。 glibc のこれらのシステムコールのラッパー関数において、nice 値の ユーザ領域 (user-land) とカーネル表現の間の変換が行われる。 変換式は以下の通り: .I "unice\ =\ 20\ \-\ knice" .LP .\"O On some systems, the range of nice values is \-20..20. いくつかのシステムでは、nice 値の範囲は \20 〜 20 である。 .LP .\"O Including .\"O .I .\"O is not required these days, but increases portability. .\"O (Indeed, .\"O .I .\"O defines the .\"O .I rusage .\"O structure with fields of type .\"O .I struct timeval .\"O defined in .\"O .IR .) 現在では .I をインクルードする必要はないが、インクルードすれば移植性を高めることができる (実際には .I で .I rusage 構造体が定義されているが、そのフィールドで使用されている .I struct timeval 型は .I で定義されている)。 .\"O .SH "SEE ALSO" .SH 関連項目 .BR nice (1), .BR renice (1), .BR fork (2), .BR capabilities (7) .sp .\"O .I Documentation/scheduler/sched-nice-design.txt .\"O in the kernel source tree (since Linux 2.6.23). (Linux 2.6.23 以降の) カーネルのソースツリー内の .I Documentation/scheduler/sched-nice-design.txt