Penguin
Blame: sched_setscheduler(2)
EditPageHistoryDiffInfoLikePages
Annotated edit history of sched_setscheduler(2) version 4, including all changes. View license author blame.
Rev Author # Line
1 perry 1 SETSCHEDULER
2 !!!SETSCHEDULER
3 NAME
4 SYNOPSIS
5 DESCRIPTION
6 RETURN VALUE
7 ERRORS
8 CONFORMING TO
9 BUGS
10 NOTE
11 SEE ALSO
12 ----
13 !!NAME
14
15
16 sched_setscheduler, sched_getscheduler - set and get scheduling algorithm/parameters
17 !!SYNOPSIS
18
19
20 __#include __
21
22
23 __int sched_setscheduler(pid_t__ ''pid''__, int__
24 ''policy''__, const struct sched_param
25 *__''p''__);__
26
27
28 __int sched_getscheduler(pid_t__
29 ''pid''__);__
30
31
32 struct sched_param {
33 ...
34 int ''sched_priority''__;
35 ...
36 };
37 __
38 !!DESCRIPTION
39
40
41 __sched_setscheduler__ sets both the scheduling policy
42 and the associated parameters for the process identified by
43 ''pid''. If ''pid'' equals zero, the scheduler of the
44 calling process will be set. The interpretation of the
45 parameter ''p'' depends on the selected policy.
46 Currently, the following three scheduling policies are
47 supported under Linux: ''SCHED_FIFO'', ''SCHED_RR'',
48 and ''SCHED_OTHER''; their respective semantics is
49 described below.
50
51
52 __sched_getscheduler__ queries the scheduling policy
53 currently applied to the process identified by ''pid''.
54 If ''pid'' equals zero, the policy of the calling process
55 will be retrieved.
56
57
58 __Scheduling Policies__
59
60
61 The scheduler is the kernel part that decides which runnable
62 process will be executed by the CPU next. The Linux
63 scheduler offers three different scheduling policies, one
64 for normal processes and two for real-time applications. A
65 static priority value ''sched_priority'' is assigned to
66 each process and this value can be changed only via system
67 calls. Conceptually, the scheduler maintains a list of
68 runnable processes for each possible ''sched_priority''
69 value, and ''sched_priority'' can have a value in the
70 range 0 to 99. In order to determine the process that runs
71 next, the Linux scheduler looks for the non-empty list with
72 the highest static priority and takes the process at the
73 head of this list. The scheduling policy determines for each
74 process, where it will be inserted into the list of
75 processes with equal static priority and how it will move
76 inside this list.
77
78
79 ''SCHED_OTHER'' is the default universal time-sharing
80 scheduler policy used by most processes, ''SCHED_FIFO''
81 and ''SCHED_RR'' are intended for special time-critical
82 applications that need precise control over the way in which
83 runnable processes are selected for execution. Processes
84 scheduled with ''SCHED_OTHER'' must be assigned the
85 static priority 0, processes scheduled under
86 ''SCHED_FIFO'' or ''SCHED_RR'' can have a static
87 priority in the range 1 to 99. Only processes with superuser
88 privileges can get a static priority higher than 0 and can
89 therefore be scheduled under ''SCHED_FIFO'' or
90 ''SCHED_RR''. The system calls
91 __sched_get_priority_min__ and
92 __sched_get_priority_max__ can be used to to find out the
93 valid priority range for a scheduling policy in a portable
94 way on all POSIX.1b conforming systems.
95
96
97 All scheduling is preemptive: If a process with a higher
98 static priority gets ready to run, the current process will
99 be preempted and returned into its wait list. The scheduling
100 policy only determines the ordering within the list of
101 runnable processes with equal static priority.
102
103
104 __SCHED_FIFO: First In-First out
105 scheduling__
106
107
108 ''SCHED_FIFO'' can only be used with static priorities
109 higher than 0, that means that when a ''SCHED_FIFO''
110 processes becomes runnable, it will always preempt
111 immediately any currently running normal ''SCHED_OTHER''
112 process. ''SCHED_FIFO'' is a simple scheduling algorithm
113 without time slicing. For processes scheduled under the
114 ''SCHED_FIFO'' policy, the following rules are applied: A
115 ''SCHED_FIFO'' process that has been preempted by another
116 process of higher priority will stay at the head of the list
117 for its priority and will resume execution as soon as all
118 processes of higher priority are blocked again. When a
119 ''SCHED_FIFO'' process becomes runnable, it will be
120 inserted at the end of the list for its priority. A call to
121 __sched_setscheduler__ or __sched_setparam__ will put
122 the ''SCHED_FIFO'' process identified by ''pid'' at
123 the end of the list if it was runnable. A process calling
124 __sched_yield__ will be put at the end of the list. No
125 other events will move a process scheduled under the
126 ''SCHED_FIFO'' policy in the wait list of runnable
127 processes with equal static priority. A ''SCHED_FIFO''
128 process runs until either it is blocked by an I/O request,
129 it is preempted by a higher priority process, or it calls
130 __sched_yield__.
131
132
133 __SCHED_RR: Round Robin scheduling__
134
135
136 ''SCHED_RR'' is a simple enhancement of
137 ''SCHED_FIFO''. Everything described above for
138 ''SCHED_FIFO'' also applies to ''SCHED_RR'', except
139 that each process is only allowed to run for a maximum time
140 quantum. If a ''SCHED_RR'' process has been running for a
141 time period equal to or longer than the time quantum, it
142 will be put at the end of the list for its priority. A
143 ''SCHED_RR'' process that has been preempted by a higher
144 priority process and subsequently resumes execution as a
145 running process will complete the unexpired portion of its
146 round robin time quantum. The length of the time quantum can
147 be retrieved by __sched_rr_get_interval__.
148
149
150 __SCHED_OTHER: Default Linux time-sharing
151 scheduling__
152
153
154 ''SCHED_OTHER'' can only be used at static priority 0.
155 ''SCHED_OTHER'' is the standard Linux time-sharing
156 scheduler that is intended for all processes that do not
157 require special static priority real-time mechanisms. The
158 process to run is chosen from the static priority 0 list
159 based on a dynamic priority that is determined only inside
160 this list. The dynamic priority is based on the nice level
161 (set by the __nice__ or __setpriority__ system call)
162 and increased for each time quantum the process is ready to
163 run, but denied to run by the scheduler. This ensures fair
164 progress among all ''SCHED_OTHER''
165 processes.
166
167
168 __Response time__
169
170
171 A blocked high priority process waiting for the I/O has a
172 certain response time before it is scheduled again. The
173 device driver writer can greatly reduce this response time
174 by using a
175 request_irq__(9).
176
177
178 __Miscellaneous__
179
180
181 Child processes inherit the scheduling algorithm and
182 parameters across a __fork__.
183
184
185 Memory locking is usually needed for real-time processes to
186 avoid paging delays, this can be done with __mlock__ or
187 __mlockall__.
188
189
190 As a non-blocking end-less loop in a process scheduled under
191 ''SCHED_FIFO'' or ''SCHED_RR'' will block all
192 processes with lower priority forever, a software developer
193 should always keep available on the console a shell
194 scheduled under a higher static priority than the tested
195 application. This will allow an emergency kill of tested
196 real-time applications that do not block or terminate as
197 expected. As ''SCHED_FIFO'' and ''SCHED_RR'' processes
198 can preempt other processes forever, only root processes are
199 allowed to activate these policies under Linux.
200
201
202 POSIX systems on which __sched_setscheduler__ and
203 __sched_getscheduler__ are available define
204 ''_POSIX_PRIORITY_SCHEDULING'' in
205 ''
206 !!RETURN VALUE
207
208
209 On success, __sched_setscheduler__ returns zero. On
210 success, __sched_getscheduler__ returns the policy for
211 the process (a non-negative integer). On error, -1 is
212 returned, ''errno'' is set appropriately.
213 !!ERRORS
214
215
216 __ESRCH__
217
218
219 The process whose ID is ''pid'' could not be
220 found.
221
222
223 __EPERM__
224
225
226 The calling process does not have appropriate privileges.
227 Only root processes are allowed to activate the
228 ''SCHED_FIFO'' and ''SCHED_RR'' policies. The process
229 calling __sched_setscheduler__ needs an effective uid
230 equal to the euid or uid of the process identified by
231 ''pid'', or it must be a superuser process.
232
233
234 __EINVAL__
235
236
237 The scheduling ''policy'' is not one of the recognized
238 policies, or the parameter ''p'' does not make sense for
239 the ''policy''.
240 !!CONFORMING TO
241
242
243 POSIX.1b (formerly POSIX.4)
244 !!BUGS
245
246
247 As of linux-1.3.81, ''SCHED_RR'' has not yet been tested
248 carefully and might not behave exactly as described or
249 required by POSIX.1b.
250 !!NOTE
251
252
253 Standard Linux is a general-purpose operating system and can
254 handle background processes, interactive applications, and
255 soft real-time applications (applications that need to
256 usually meet timing deadlines). This man page is directed at
257 these kinds of applications.
258
259
260 Standard Linux is ''not'' designed to support hard
261 real-time applications, that is, applications in which
262 deadlines (often much shorter than a second) must be
263 guaranteed or the system will fail catastrophically. Like
264 all general-purpose operating systems, Linux is designed to
265 maximize average case performance instead of worst case
266 performance. Linux's worst case performance for interrupt
267 handling is much poorer than its average case, its various
268 kernel locks (such as for SMP) produce long maximum wait
269 times, and many of its performance improvement techniques
270 decrease average time by increasing worst-case time. For
271 most situations, that's what you want, but if you truly are
272 developing a hard real-time application, consider using hard
273 real-time extensions to Linux such as RTLinux
274 (http://www.rtlinux.org) or use a different operating system
275 designed specifically for hard real-time
276 applications.
277 !!SEE ALSO
278
279
4 perry 280 sched_setparam(2), __sched_getparam__(2),
281 sched_yield(2), __sched_get_priority_max__(2),
282 sched_get_priority_min(2), nice(2),
1 perry 283 setpriority(2), getpriority(2),
284 mlockall(2), munlockall(2), mlock(2),
285 munlock(2)
286
287
288 ''Programming for the real world - POSIX.4'' by Bill O.
289 Gallmeister, O'Reilly
290 ''
291 IEEE Std 1003.1b-1993'' (POSIX.1b standard)''
292 ISO/IEC 9945-1:1996'' - This is the new 1996 revision of
293 POSIX.1 which contains in one single standard POSIX.1(1990),
294 POSIX.1b(1993), POSIX.1c(1995), and
295 POSIX.1i(1995).
296 ----
This page is a man page (or other imported legacy content). We are unable to automatically determine the license status of this page.