.\" Copyright (c) 1980, 1991 The Regents of the University of California. .\" All rights reserved. .\" .\" %%%LICENSE_START(BSD_4_CLAUSE_UCB) .\" 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. .\" %%%LICENSE_END .\" .\" @(#)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 .\" .\"******************************************************************* .\" .\" This file was generated with po4a. Translate the source file. .\" .\"******************************************************************* .\" .\" 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 .\" Updated 2013-05-06, Akihiro MOTOKI .\" .TH GETPRIORITY 2 2017\-09\-15 Linux "Linux Programmer's Manual" .SH 名前 getpriority, setpriority \- プログラムのスケジューリングの優先度を取得/設定する .SH 書式 \fB#include \fP .br \fB#include \fP .PP \fBint getpriority(int \fP\fIwhich\fP\fB, id_t \fP\fIwho\fP\fB);\fP .br \fBint setpriority(int \fP\fIwhich\fP\fB, id_t \fP\fIwho\fP\fB, int \fP\fIprio\fP\fB);\fP .SH 説明 The scheduling priority of the process, process group, or user, as indicated by \fIwhich\fP and \fIwho\fP is obtained with the \fBgetpriority\fP() call and set with the \fBsetpriority\fP() call. The process attribute dealt with by these system calls is the same attribute (also known as the "nice" value) that is dealt with by \fBnice\fP(2). .PP \fIwhich\fP の値は \fBPRIO_PROCESS\fP, \fBPRIO_PGRP\fP, \fBPRIO_USER\fP, のどれか一つで、 \fIwho\fP は \fIwhich\fP に応じて解釈される (\fBPRIO_PROCESS\fP だとプロセス識別子、 \fBPRIO_PGRP\fP だとプロセスグループ識別子、 \fBPRIO_USER\fP だと UID (ユーザーID) と解釈される)。 \fIwho\fP がゼロならば、(それぞれ)呼び出したプロセス、 呼び出したプロセスのプロセスグループ、 呼び出したプロセスの実UID を意味する。 .PP \fIprio\fP 引数は \-20 から 19 の範囲の値で (但し以下の「注意」を参照)、 \-20 が最高優先度で、 19 が最低優先度である。優先度をこの範囲外に設定しようとした場合は、値は黙ってこの範囲となる。デフォルトの優先度は 0 である; 小さな数字ほど、プロセスのスケジューリング優先度が高くなる。 .PP \fBgetpriority\fP() コールは指定したプロセスの中の最も高い優先度 (数値的には最小の値) を返す。 \fBsetpriority\fP() コールは指定したプロセス全ての優先度を指定した値に設定する。 .PP Traditionally, only a privileged process could lower the nice value (i.e., set a higher priority). However, since Linux 2.6.12, an unprivileged process can decrease the nice value of a target process that has a suitable \fBRLIMIT_NICE\fP soft limit; see \fBgetrlimit\fP(2) for details. .SH 返り値 On success, \fBgetpriority\fP() returns the calling thread's nice value, which may be a negative number. On error, it returns \-1 and sets \fIerrno\fP to indicate the cause of the error. .PP \fBgetpriority\fP() は成功した場合にも \-1 の値を返す可能性があるので、 呼び出しの前に外部変数の \fIerrno\fP をクリアし、呼び出しの後に返り値の \-1 が正当な値か エラーかを判別する必要がある。 .PP 成功すると、 \fBsetpriority\fP() は 0 を返す。 エラーの場合、\-1 を返し、 \fIerrno\fP にエラーの原因を示す値を設定する。 .SH エラー .TP \fBEINVAL\fP \fIwhich\fP が \fBPRIO_PROCESS\fP, \fBPRIO_PGRP\fP, \fBPRIO_USER\fP のいずれでもない。 .TP \fBESRCH\fP \fIwhich\fP と \fIwho\fP で指定されたプロセスが存在しない。 .PP 上記のものに加えて \fBsetpriority\fP() では以下のエラーがある: .TP \fBEACCES\fP The caller attempted to set a lower nice value (i.e., a higher process priority), but did not have the required privilege (on Linux: did not have the \fBCAP_SYS_NICE\fP capability). .TP \fBEPERM\fP プロセスは見つかったが、そのプロセスの実効 (effective) UID が 呼び出し元の実効UID にも実 (real) UID にも一致せず、 呼び出し元が特権も持っていなかった (Linux の場合、 \fBCAP_SYS_NICE\fP ケーパビリティがなかった)。 以下の「注意」も参照のこと。 .SH 準拠 POSIX.1\-2001, POSIX.1\-2008, SVr4, 4.4BSD (これらのインターフェースは 4.2BSD で初めて登場した) .SH 注意 nice 値の詳細は \fBsched\fP(7) を参照のこと。 .PP \fINote\fP: the addition of the "autogroup" feature in Linux 2.6.38 means that the nice value no longer has its traditional effect in many circumstances. For details, see \fBsched\fP(7). .PP \fBfork\fP(2) で作成された子プロセスは、 親プロセスの nice 値を継承する。 \fBexecve\fP(2) の前後で nice 値は保存される。 .PP \fBEPERM\fP が発生する条件の詳細はシステムに依存する。 上記の説明は POSIX.1\-2001 のものであり、全ての System\ V 風システムは これに従っているようである。 2.6.12 より前の Linux カーネルでは、呼び出し元の実 UID または 実効 UID がプロセス \fIwho\fP の (実効 UID でなく) 実 UID に一致する必要がある。 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 以降と同じ動作をする。 .PP .\" 現在では \fI\fP をインクルードする必要はないが、インクルードすれば移植性を高めることができる (実際には \fI\fP で \fIrusage\fP 構造体が定義されているが、そのフィールドで使用されている \fIstruct timeval\fP 型は \fI\fP で定義されている)。 .SS "C ライブラリとカーネルの違い" カーネル内部では、nice 値は実際には 40 〜 1 の範囲を使って 表現されており (負の値はエラーコードとなるため)、こちらの値が システムコール \fBsetpriority\fP() と \fBgetpriority\fP() で使用されている。 glibc のこれらのシステムコールのラッパー関数において、nice 値の ユーザー領域 (user\-land) とカーネル表現の間の変換が行われる。 変換式は \fIunice\ =\ 20\ \-\ knice\fP となる。 (したがって、カーネルの 40..1 の範囲はユーザー空間で見える \-20..19 の範囲に対応する。) .SH バグ POSIX では nice 値はプロセス単位の設定となっている。 一方、 現在の POSIX スレッドの Linux/NPTL 実装では、 nice 値はスレッド単位の属性である。 同じプロセスの別々のスレッドが異なる nice 値を持つ場合がある。 移植性が必要なアプリケーションではこの Linux の動作を前提するのは避けるべきである。 Linux の動作は将来標準に準拠した動作になるかもしれない。 .SH 関連項目 \fBnice\fP(1), \fBrenice\fP(1), \fBfork\fP(2), \fBcapabilities\fP(7), \fBsched\fP(7) .PP Linux カーネルのソースツリー内の \fIDocumentation/scheduler/sched\-nice\-design.txt\fP (Linux 2.6.23 以降) .SH この文書について この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 5.10 の一部である。プロジェクトの説明とバグ報告に関する情報は \%https://www.kernel.org/doc/man\-pages/ に書かれている。