]>
Commit | Line | Data |
---|---|---|
270d15a2 | 1 | .\" Copyright (C) 2014 Michael Kerrisk <mtk.manpages@gmail.com> |
fea681da | 2 | .\" |
270d15a2 MK |
3 | .\" %%%LICENSE_START(VERBATIM) |
4 | .\" Permission is granted to make and distribute verbatim copies of this | |
5 | .\" manual provided the copyright notice and this permission notice are | |
6 | .\" preserved on all copies. | |
fea681da | 7 | .\" |
270d15a2 MK |
8 | .\" Permission is granted to copy and distribute modified versions of this |
9 | .\" manual under the conditions for verbatim copying, provided that the | |
10 | .\" entire resulting derived work is distributed under the terms of a | |
11 | .\" permission notice identical to this one. | |
fea681da | 12 | .\" |
270d15a2 MK |
13 | .\" Since the Linux kernel and libraries are constantly changing, this |
14 | .\" manual page may be incorrect or out-of-date. The author(s) assume no | |
15 | .\" responsibility for errors or omissions, or for damages resulting from | |
16 | .\" the use of the information contained herein. The author(s) may not | |
17 | .\" have taken the same level of care in the production of this manual, | |
18 | .\" which is licensed free of charge, as they might when working | |
19 | .\" professionally. | |
fea681da | 20 | .\" |
270d15a2 MK |
21 | .\" Formatted or processed versions of this manual, if unaccompanied by |
22 | .\" the source, must acknowledge the copyright and authors of this work. | |
6a8d8745 | 23 | .\" %%%LICENSE_END |
fea681da | 24 | .\" |
fea681da | 25 | .\" |
4b8c67d9 | 26 | .TH SCHED_SETSCHEDULER 2 2017-09-15 "Linux" "Linux Programmer's Manual" |
fea681da MK |
27 | .SH NAME |
28 | sched_setscheduler, sched_getscheduler \- | |
a3a22b7f | 29 | set and get scheduling policy/parameters |
fea681da | 30 | .SH SYNOPSIS |
92c37d8c | 31 | .nf |
fea681da | 32 | .B #include <sched.h> |
68e4db0a | 33 | .PP |
fea681da | 34 | .BI "int sched_setscheduler(pid_t " pid ", int " policy , |
92c37d8c | 35 | .BI " const struct sched_param *" param ); |
68e4db0a | 36 | .PP |
fea681da | 37 | .BI "int sched_getscheduler(pid_t " pid ); |
fea681da MK |
38 | .fi |
39 | .SH DESCRIPTION | |
270d15a2 | 40 | The |
e511ffb6 | 41 | .BR sched_setscheduler () |
270d15a2 MK |
42 | system call |
43 | sets both the scheduling policy and parameters for the | |
81bd66da | 44 | thread whose ID is specified in \fIpid\fP. |
c13182ef | 45 | If \fIpid\fP equals zero, the |
81bd66da | 46 | scheduling policy and parameters of the calling thread will be set. |
efeece04 | 47 | .PP |
270d15a2 MK |
48 | The scheduling parameters are specified in the |
49 | .I param | |
b9136726 | 50 | argument, which is a pointer to a structure of the following form: |
efeece04 | 51 | .PP |
270d15a2 | 52 | .in +4n |
b8302363 | 53 | .EX |
270d15a2 MK |
54 | struct sched_param { |
55 | ... | |
56 | int sched_priority; | |
57 | ... | |
58 | }; | |
b8302363 | 59 | .EE |
e646a1ba | 60 | .in |
efeece04 | 61 | .PP |
270d15a2 MK |
62 | In the current implementation, the structure contains only one field, |
63 | .IR sched_priority . | |
c13182ef | 64 | The interpretation of |
270d15a2 MK |
65 | .I param |
66 | depends on the selected policy. | |
efeece04 | 67 | .PP |
4e592516 | 68 | Currently, Linux supports the following "normal" |
270d15a2 MK |
69 | (i.e., non-real-time) scheduling policies as values that may be specified in |
70 | .IR policy : | |
a3a22b7f | 71 | .TP 14 |
a1d5601b MK |
72 | .BR SCHED_OTHER |
73 | the standard round-robin time-sharing policy; | |
c13182ef | 74 | .\" In the 2.6 kernel sources, SCHED_OTHER is actually called |
92c37d8c | 75 | .\" SCHED_NORMAL. |
a3a22b7f MK |
76 | .TP |
77 | .BR SCHED_BATCH | |
78 | for "batch" style execution of processes; and | |
79 | .TP | |
80 | .BR SCHED_IDLE | |
81 | for running | |
82 | .I very | |
83 | low priority background jobs. | |
84 | .PP | |
270d15a2 MK |
85 | For each of the above policies, |
86 | .IR param\->sched_priority | |
87 | must be 0. | |
efeece04 | 88 | .PP |
270d15a2 | 89 | Various "real-time" policies are also supported, |
a3a22b7f | 90 | for special time-critical applications that need precise control over |
270d15a2 MK |
91 | the way in which runnable threads are selected for execution. |
92 | For the rules governing when a process may use these policies, see | |
93 | .BR sched (7). | |
94 | The real-time policies that may be specified in | |
95 | .IR policy | |
96 | are: | |
a3a22b7f MK |
97 | .TP 14 |
98 | .BR SCHED_FIFO | |
99 | a first-in, first-out policy; and | |
100 | .TP | |
101 | .BR SCHED_RR | |
102 | a round-robin policy. | |
103 | .PP | |
270d15a2 MK |
104 | For each of the above policies, |
105 | .IR param\->sched_priority | |
106 | specifies a scheduling priority for the thread. | |
ab3d0245 | 107 | This is a number in the range returned by calling |
60a90ecd MK |
108 | .BR sched_get_priority_min (2) |
109 | and | |
59ab8fcf | 110 | .BR sched_get_priority_max (2) |
270d15a2 MK |
111 | with the specified |
112 | .IR policy . | |
113 | On Linux, these system calls return, respectively, 1 and 99. | |
efeece04 | 114 | .PP |
93414d35 MK |
115 | Since Linux 2.6.32, the |
116 | .B SCHED_RESET_ON_FORK | |
117 | flag can be ORed in | |
118 | .I policy | |
119 | when calling | |
120 | .BR sched_setscheduler (). | |
121 | As a result of including this flag, children created by | |
122 | .BR fork (2) | |
123 | do not inherit privileged scheduling policies. | |
fd04afa8 | 124 | See |
270d15a2 MK |
125 | .BR sched (7) |
126 | for details. | |
efeece04 | 127 | .PP |
e511ffb6 | 128 | .BR sched_getscheduler () |
270d15a2 MK |
129 | returns the current scheduling policy of the thread |
130 | identified by \fIpid\fP. | |
131 | If \fIpid\fP equals zero, the policy of the | |
132 | calling thread will be retrieved. | |
47297adb | 133 | .SH RETURN VALUE |
fea681da | 134 | On success, |
e511ffb6 | 135 | .BR sched_setscheduler () |
c13182ef | 136 | returns zero. |
fea681da | 137 | On success, |
e511ffb6 | 138 | .BR sched_getscheduler () |
81bd66da | 139 | returns the policy for the thread (a nonnegative integer). |
270d15a2 | 140 | On error, both calls return \-1, and |
fea681da MK |
141 | .I errno |
142 | is set appropriately. | |
143 | .SH ERRORS | |
144 | .TP | |
145 | .B EINVAL | |
b61826c0 | 146 | Invalid arguments: |
94417494 | 147 | .I pid |
b61826c0 MK |
148 | is negative or |
149 | .I param | |
150 | is NULL. | |
151 | .TP | |
152 | .B EINVAL | |
6a6dd344 | 153 | .RB ( sched_setscheduler ()) |
b61826c0 MK |
154 | .I policy |
155 | is not one of the recognized policies. | |
156 | .TP | |
157 | .B EINVAL | |
6a6dd344 | 158 | .RB ( sched_setscheduler ()) |
b61826c0 MK |
159 | .I param |
160 | does not make sense for the specified | |
161 | .IR policy . | |
fea681da MK |
162 | .TP |
163 | .B EPERM | |
81bd66da | 164 | The calling thread does not have appropriate privileges. |
fea681da MK |
165 | .TP |
166 | .B ESRCH | |
81bd66da | 167 | The thread whose ID is \fIpid\fP could not be found. |
47297adb | 168 | .SH CONFORMING TO |
428a4469 | 169 | POSIX.1-2001, POSIX.1-2008 (but see BUGS below). |
c00194ab | 170 | The \fBSCHED_BATCH\fP and \fBSCHED_IDLE\fP policies are Linux-specific. |
92c37d8c | 171 | .SH NOTES |
270d15a2 | 172 | Further details of the semantics of all of the above "normal" |
16109ab3 MK |
173 | and "real-time" scheduling policies can be found in the |
174 | .BR sched (7) | |
175 | manual page. | |
176 | That page also describes an additional policy, | |
177 | .BR SCHED_DEADLINE , | |
178 | which is settable only via | |
179 | .BR sched_setattr (2). | |
efeece04 | 180 | .PP |
270d15a2 MK |
181 | POSIX systems on which |
182 | .BR sched_setscheduler () | |
183 | and | |
184 | .BR sched_getscheduler () | |
185 | are available define | |
186 | .B _POSIX_PRIORITY_SCHEDULING | |
187 | in \fI<unistd.h>\fP. | |
efeece04 | 188 | .PP |
97bc0094 | 189 | POSIX.1 does not detail the permissions that an unprivileged |
81bd66da | 190 | thread requires in order to call |
f902bebc | 191 | .BR sched_setscheduler (), |
97bc0094 MK |
192 | and details vary across systems. |
193 | For example, the Solaris 7 manual page says that | |
81bd66da MK |
194 | the real or effective user ID of the caller must |
195 | match the real user ID or the save set-user-ID of the target. | |
d5999511 MK |
196 | .PP |
197 | The scheduling policy and parameters are in fact per-thread | |
198 | attributes on Linux. | |
199 | The value returned from a call to | |
200 | .BR gettid (2) | |
201 | can be passed in the argument | |
202 | .IR pid . | |
203 | Specifying | |
204 | .I pid | |
ab3d0245 | 205 | as 0 will operate on the attributes of the calling thread, |
d5999511 MK |
206 | and passing the value returned from a call to |
207 | .BR getpid (2) | |
ab3d0245 | 208 | will operate on the attributes of the main thread of the thread group. |
d5999511 MK |
209 | (If you are using the POSIX threads API, then use |
210 | .BR pthread_setschedparam (3), | |
211 | .BR pthread_getschedparam (3), | |
212 | and | |
213 | .BR pthread_setschedprio (3), | |
214 | instead of the | |
215 | .BR sched_* (2) | |
216 | system calls.) | |
d61ff56a | 217 | .SH BUGS |
99940e05 | 218 | POSIX.1 says that on success, |
d61ff56a MK |
219 | .BR sched_setscheduler () |
220 | should return the previous scheduling policy. | |
221 | Linux | |
222 | .BR sched_setscheduler () | |
223 | does not conform to this requirement, | |
224 | since it always returns 0 on success. | |
47297adb | 225 | .SH SEE ALSO |
ca8a0bd2 MK |
226 | .ad l |
227 | .nh | |
ac30de07 | 228 | .BR chrt (1), |
fea681da MK |
229 | .BR nice (2), |
230 | .BR sched_get_priority_max (2), | |
231 | .BR sched_get_priority_min (2), | |
232 | .BR sched_getaffinity (2), | |
270d15a2 | 233 | .BR sched_getattr (2), |
fea681da MK |
234 | .BR sched_getparam (2), |
235 | .BR sched_rr_get_interval (2), | |
236 | .BR sched_setaffinity (2), | |
270d15a2 | 237 | .BR sched_setattr (2), |
fea681da MK |
238 | .BR sched_setparam (2), |
239 | .BR sched_yield (2), | |
240 | .BR setpriority (2), | |
a18e2edb | 241 | .BR capabilities (7), |
270d15a2 MK |
242 | .BR cpuset (7), |
243 | .BR sched (7) | |
ab13a138 | 244 | .ad |