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