File: sched_setscheduler.2

package info (click to toggle)
manpages-ja 0.5.0.0.20210215%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 28,568 kB
  • sloc: perl: 161; makefile: 58
file content (172 lines) | stat: -rw-r--r-- 9,443 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
.\" Copyright (C) 2014 Michael Kerrisk <mtk.manpages@gmail.com>
.\"
.\" %%%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 <yosshy@jedi.seg.kobe-u.ac.jp>
.\" Modified Sun Nov 21 19:36:18 JST 1999
.\"         by HANATAKA Shinya <hanataka@abyss.rim.or.jp>
.\" Updated Wed Jan  1 JST 2003 by Kentaro Shirakata <argrath@ub32.org>
.\" Updated 2005-02-24, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
.\" 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 <amotoki@gmail.com>
.\" Updated 2013-05-01, Akihiro MOTOKI <amotoki@gmail.com>
.\" Updated 2013-05-06, Akihiro MOTOKI <amotoki@gmail.com>
.\"
.TH SCHED_SETSCHEDULER 2 2014\-10\-02 Linux "Linux Programmer's Manual"
.SH 名前
sched_setscheduler, sched_getscheduler \- スケジューリングポリシーとパラメーターを設定/取得する
.SH 書式
.nf
\fB#include <sched.h>\fP
.sp
\fBint sched_setscheduler(pid_t \fP\fIpid\fP\fB, int \fP\fIpolicy\fP\fB,\fP
.br
\fB                       const struct sched_param *\fP\fIparam\fP\fB);\fP
.sp
\fBint sched_getscheduler(pid_t \fP\fIpid\fP\fB);\fP
.sp
.fi
.SH 説明
\fBsched_setscheduler\fP() システムコールは、 \fIpid\fP で指定された ID
を持つスレッドのスケジューリングポリシーとスケジューリングパラメーターの両方を設定する。 \fIpid\fP が 0
の場合、呼び出したスレッド自身のスケジューリングポリシーとスケジューリングパラメーターが設定される。

スケジューリングパラメーターは \fIparam\fP 引き数で、以下の形式の構造体へのポインターを指定する。

.nf
.in +4n
struct sched_param {
    ...
    int sched_priority;
    ...
};
.in
.fi

現在の実装では、この構造体のフィールドは \fIsched_priority\fP だけである。 \fIparam\fP
がどのように解釈されるかは選択されたポリシーによって変わる。

現在のところ、 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 でなければならない。

どの実行可能スレッドを選択するかについて、より正確な制御を必要とする 時間の制約が厳しい特別なアプリケーション用として、
いろいろな「リアルタイム」ポリシーもサポートされている。 プロセスがこれらのポリシーをいつ使用できるかを決めるルールについては、\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 を返す。

Linux 2.6.32 以降では、 \fBsched_setscheduler\fP() を呼び出す際に \fIpolicy\fP に
\fBSCHED_RESET_ON_FORK\fP フラグを OR で指定できる。このフラグが指定されると、 \fBfork\fP(2)
で作成された子プロセスは特権が必要なスケジューリングポリシーを継承しない。 詳細は \fBsched\fP(7) を参照。

\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 (但し、下記のバグの節も参照)。 \fBSCHED_BATCH\fP と \fBSCHED_IDLE\fP ポリシーは Linux
固有である。
.SH 注意
上記の「通常」および「リアルタイム」スケジューリングポリシーの動作の詳細な説明は \fBsched\fP(7) にある。

POSIX システムでは \fI<unistd.h>\fP に \fB_POSIX_PRIORITY_SCHEDULING\fP
が定義されている場合にのみ \fBsched_setscheduler\fP()  と \fBsched_getscheduler\fP()  が使用できる。

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 では、成功時に \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 プロジェクトのリリース 3.79 の一部
である。プロジェクトの説明とバグ報告に関する情報は
http://www.kernel.org/doc/man\-pages/ に書かれている。