.\" Copyright (C) 2014 Michael Kerrisk .\" .\" %%%LICENSE_START(VERBATIM) .\" Permission is granted to make and distribute verbatim copies of this .\" manual provided the copyright notice and this permission notice are .\" preserved on all copies. .\" .\" Permission is granted to copy and distribute modified versions of this .\" manual under the conditions for verbatim copying, provided that the .\" entire resulting derived work is distributed under the terms of a .\" permission notice identical to this one. .\" .\" Since the Linux kernel and libraries are constantly changing, this .\" manual page may be incorrect or out-of-date. The author(s) assume no .\" responsibility for errors or omissions, or for damages resulting from .\" the use of the information contained herein. The author(s) may not .\" have taken the same level of care in the production of this manual, .\" which is licensed free of charge, as they might when working .\" professionally. .\" .\" Formatted or processed versions of this manual, if unaccompanied by .\" the source, must acknowledge the copyright and authors of this work. .\" %%%LICENSE_END .\" .\" .\"******************************************************************* .\" .\" This file was generated with po4a. Translate the source file. .\" .\"******************************************************************* .\" .\" Japanese Version Copyright (c) 1996 Akira Yoshiyama .\" all rights reserved. .\" Translated Thu Jul 11 01:42:52 JST 1996 .\" by Akira Yoshiyama .\" Modified Sun Nov 21 19:36:18 JST 1999 .\" by HANATAKA Shinya .\" Updated Wed Jan 1 JST 2003 by Kentaro Shirakata .\" Updated 2005-02-24, Akihiro MOTOKI .\" Updated & Modified 2005-10-10, Akihiro MOTOKI .\" Updated 2006-04-16, Akihiro MOTOKI, Catch up to LDP v2.28 .\" Updated 2007-10-13, Akihiro MOTOKI, LDP v2.65 .\" Updated 2008-08-13, Akihiro MOTOKI, LDP v3.05 .\" Updated 2012-06-04, Akihiro MOTOKI .\" Updated 2013-05-01, Akihiro MOTOKI .\" Updated 2013-05-06, Akihiro MOTOKI .\" .TH SCHED_SETSCHEDULER 2 " 2017\-09\-15" Linux "Linux Programmer's Manual" .SH 名前 sched_setscheduler, sched_getscheduler \- スケジューリングポリシーとパラメーターを設定/取得する .SH 書式 .nf \fB#include \fP .PP \fBint sched_setscheduler(pid_t \fP\fIpid\fP\fB, int \fP\fIpolicy\fP\fB,\fP \fB const struct sched_param *\fP\fIparam\fP\fB);\fP .PP \fBint sched_getscheduler(pid_t \fP\fIpid\fP\fB);\fP .fi .SH 説明 \fBsched_setscheduler\fP() システムコールは、 \fIpid\fP で指定された ID を持つスレッドのスケジューリングポリシーとスケジューリングパラメーターの両方を設定する。 \fIpid\fP が 0 の場合、呼び出したスレッド自身のスケジューリングポリシーとスケジューリングパラメーターが設定される。 .PP スケジューリングパラメーターは \fIparam\fP 引数で、以下の形式の構造体へのポインターを指定する。 .PP .in +4n .EX struct sched_param { ... int sched_priority; ... }; .EE .in .PP 現在の実装では、この構造体のフィールドは \fIsched_priority\fP だけである。 \fIparam\fP がどのように解釈されるかは選択されたポリシーによって変わる。 .PP 現在のところ、 Linux では、 以下の「通常」の (つまり、リアルタイムではない) スケジューリングポリシーが、 \fIpolicy\fP に指定できる値としてサポートされている。 .TP 14 \fBSCHED_OTHER\fP .\" In the 2.6 kernel sources, SCHED_OTHER is actually called .\" SCHED_NORMAL. 標準の、ラウンドロビンによる時分割型のスケジューリングポリシー。 .TP \fBSCHED_BATCH\fP 「バッチ」形式でのプロセスの実行用。 .TP \fBSCHED_IDLE\fP 「非常に」低い優先度で動作するバックグラウンドジョブ用。 .PP 上記のどのポリシーの場合でも、 \fIparam\->sched_priority\fP は 0 でなければならない。 .PP どの実行可能スレッドを選択するかについて、より正確な制御を必要とする 時間の制約が厳しい特別なアプリケーション用として、 いろいろな「リアルタイム」ポリシーもサポートされている。 プロセスがこれらのポリシーをいつ使用できるかを決めるルールについては、\fBsched\fP(7) を参照。 \fIpolicy\fP には以下のリアルタイムポリシーを指定できる。 .TP 14 \fBSCHED_FIFO\fP ファーストイン、ファーストアウト型のポリシー。 .TP \fBSCHED_RR\fP ラウンドロビン型のポリシー。 .PP 上記のどのポリシーの場合でも、 \fIparam\->sched_priority\fP はそのスレッドのスケジューリングポリシーを指定する。 指定された \fIpolicy\fP で \fIsched_get_priority_min\fP(2) と \fIsched_get_priority_max\fP(2) を呼び出した返り値の範囲の数字を指定する。 Linux では、これらのシステムコールはそれぞれ 1 と 99 を返す。 .PP Linux 2.6.32 以降では、 \fBsched_setscheduler\fP() を呼び出す際に \fIpolicy\fP に \fBSCHED_RESET_ON_FORK\fP フラグを OR で指定できる。このフラグが指定されると、 \fBfork\fP(2) で作成された子プロセスは特権が必要なスケジューリングポリシーを継承しない。 詳細は \fBsched\fP(7) を参照。 .PP \fBsched_getscheduler\fP() は \fIpid\fP で識別されるスレッドの現在のスケジューリングポリシーを返す。\fIpid\fP が 0 ならば、呼び出した スレッド自身のスケジューリングポリシーが返される。 .SH 返り値 成功した場合、 \fBsched_setscheduler\fP() は 0 を返す。 成功した場合、 \fBsched_getscheduler\fP() は現在のそのスレッドのポリシー (非負の整数) を返す。 エラーの場合、 どちらのコールも \-1 を返し、 \fIerrno\fP が適切に設定される。 .SH エラー .TP \fBEINVAL\fP 無効な引数: \fIpid\fP が負である、または \fIparam\fP が NULL である。 .TP \fBEINVAL\fP (\fBsched_setscheduler\fP()) \fIpolicy\fP が認識できるポリシーではない。 .TP \fBEINVAL\fP (\fBsched_setscheduler\fP()) 引数 \fIparam\fP が指定された \fIpolicy\fP では意味を持たない。 .TP \fBEPERM\fP 呼び出したスレッドが適切な特権を持っていない。 .TP \fBESRCH\fP ID が \fIpid\fP のスレッドが見つからなかった。 .SH 準拠 POSIX.1\-2001, POSIX.1\-2008 (但し、下記のバグの節も参照)。 \fBSCHED_BATCH\fP と \fBSCHED_IDLE\fP ポリシーは Linux 固有である。 .SH 注意 Further details of the semantics of all of the above "normal" and "real\-time" scheduling policies can be found in the \fBsched\fP(7) manual page. That page also describes an additional policy, \fBSCHED_DEADLINE\fP, which is settable only via \fBsched_setattr\fP(2). .PP POSIX システムでは \fI\fP に \fB_POSIX_PRIORITY_SCHEDULING\fP が定義されている場合にのみ \fBsched_setscheduler\fP() と \fBsched_getscheduler\fP() が使用できる。 .PP POSIX.1 は、非特権スレッドが \fBsched_setscheduler\fP() を呼び出すために必要な権限の詳細を規定しておらず、 詳細はシステムにより異なる。 例えば、Solaris 7 のマニュアルページでは、 呼び出し元の実ユーザー ID または実効ユーザー ID が 設定対象の実ユーザー ID か保存 (save) set\-user\-ID と 一致していなければならない、となっている。 .PP Linux では、 スケジューリングポリシーとスケジューリングパラメーターは、 実際にはスレッド単位の属性である。 \fBgettid\fP(2) の呼び出しの返り値をこのシステムコールの \fIpid\fP 引数として渡すことができる。 \fIpid\fP に 0 を指定すると、 呼び出し元のスレッドの属性が設定される。 \fBgetpid\fP(2) コールからの返り値を \fIpid\fP に指定すると、 スレッドグループのメインスレッドの属性が設定される (POSIX スレッド API を使用している場合は、 \fBsched_*\fP(2) システムコールの代わりに \fBpthread_setschedparam\fP(3), \fBpthread_getschedparam\fP(3), and \fBpthread_setschedprio\fP(3) を使用すること)。 .SH バグ POSIX.1 では、成功時に \fBsched_setscheduler\fP() は直前のスケジューリングポリシーを返すべきとされている。 Linux の \fBsched_setscheduler\fP() はこの要求仕様に準拠しておらず、 成功時には常に 0 を返す。 .SH 関連項目 .ad l .nh \fBchrt\fP(1), \fBnice\fP(2), \fBsched_get_priority_max\fP(2), \fBsched_get_priority_min\fP(2), \fBsched_getaffinity\fP(2), \fBsched_getattr\fP(2), \fBsched_getparam\fP(2), \fBsched_rr_get_interval\fP(2), \fBsched_setaffinity\fP(2), \fBsched_setattr\fP(2), \fBsched_setparam\fP(2), \fBsched_yield\fP(2), \fBsetpriority\fP(2), \fBcapabilities\fP(7), \fBcpuset\fP(7), \fBsched\fP(7) .ad .SH この文書について この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 5.10 の一部である。プロジェクトの説明とバグ報告に関する情報は \%https://www.kernel.org/doc/man\-pages/ に書かれている。