1 .\" Copyright (C) 2014 Michael Kerrisk <mtk.manpages@gmail.com>
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.
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.
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
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
26 .TH SCHED_SETSCHEDULER 2 2015-08-08 "Linux" "Linux Programmer's Manual"
28 sched_setscheduler, sched_getscheduler \-
29 set and get scheduling policy/parameters
34 .BI "int sched_setscheduler(pid_t " pid ", int " policy ,
36 .BI " const struct sched_param *" param );
38 .BI "int sched_getscheduler(pid_t " pid );
42 .BR sched_setscheduler ()
44 sets both the scheduling policy and parameters for the
45 thread whose ID is specified in \fIpid\fP.
46 If \fIpid\fP equals zero, the
47 scheduling policy and parameters of the calling thread will be set.
49 The scheduling parameters are specified in the
51 argument, which is a pointer to a structure of the following form:
63 In the current implementation, the structure contains only one field,
67 depends on the selected policy.
69 Currently, Linux supports the following "normal"
70 (i.e., non-real-time) scheduling policies as values that may be specified in
74 the standard round-robin time-sharing policy;
75 .\" In the 2.6 kernel sources, SCHED_OTHER is actually called
79 for "batch" style execution of processes; and
84 low priority background jobs.
86 For each of the above policies,
87 .IR param\->sched_priority
90 Various "real-time" policies are also supported,
91 for special time-critical applications that need precise control over
92 the way in which runnable threads are selected for execution.
93 For the rules governing when a process may use these policies, see
95 The real-time policies that may be specified in
100 a first-in, first-out policy; and
103 a round-robin policy.
105 For each of the above policies,
106 .IR param\->sched_priority
107 specifies a scheduling priority for the thread.
108 This is a number in the range returned by calling
109 .BR sched_get_priority_min (2)
111 .BR sched_get_priority_max (2)
114 On Linux, these system calls return, respectively, 1 and 99.
116 Since Linux 2.6.32, the
117 .B SCHED_RESET_ON_FORK
121 .BR sched_setscheduler ().
122 As a result of including this flag, children created by
124 do not inherit privileged scheduling policies.
129 .BR sched_getscheduler ()
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.
136 .BR sched_setscheduler ()
139 .BR sched_getscheduler ()
140 returns the policy for the thread (a nonnegative integer).
141 On error, both calls return \-1, and
143 is set appropriately.
154 .RB ( sched_setscheduler ())
156 is not one of the recognized policies.
159 .RB ( sched_setscheduler ())
161 does not make sense for the specified
165 The calling thread does not have appropriate privileges.
168 The thread whose ID is \fIpid\fP could not be found.
170 POSIX.1-2001, POSIX.1-2008 (but see BUGS below).
171 The \fBSCHED_BATCH\fP and \fBSCHED_IDLE\fP policies are Linux-specific.
173 Further details of the semantics of all of the above "normal"
174 and "real-time" scheduling policies can be found in the
177 That page also describes an additional policy,
179 which is settable only via
180 .BR sched_setattr (2).
182 POSIX systems on which
183 .BR sched_setscheduler ()
185 .BR sched_getscheduler ()
187 .B _POSIX_PRIORITY_SCHEDULING
190 POSIX.1 does not detail the permissions that an unprivileged
191 thread requires in order to call
192 .BR sched_setscheduler (),
193 and details vary across systems.
194 For example, the Solaris 7 manual page says that
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.
198 The scheduling policy and parameters are in fact per-thread
200 The value returned from a call to
202 can be passed in the argument
206 as 0 will operate on the attributes of the calling thread,
207 and passing the value returned from a call to
209 will operate on the attributes of the main thread of the thread group.
210 (If you are using the POSIX threads API, then use
211 .BR pthread_setschedparam (3),
212 .BR pthread_getschedparam (3),
214 .BR pthread_setschedprio (3),
219 POSIX.1 says that on success,
220 .BR sched_setscheduler ()
221 should return the previous scheduling policy.
223 .BR sched_setscheduler ()
224 does not conform to this requirement,
225 since it always returns 0 on success.
231 .BR sched_get_priority_max (2),
232 .BR sched_get_priority_min (2),
233 .BR sched_getaffinity (2),
234 .BR sched_getattr (2),
235 .BR sched_getparam (2),
236 .BR sched_rr_get_interval (2),
237 .BR sched_setaffinity (2),
238 .BR sched_setattr (2),
239 .BR sched_setparam (2),
242 .BR capabilities (7),