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 2017-09-15 "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 ,
35 .BI " const struct sched_param *" param );
37 .BI "int sched_getscheduler(pid_t " pid );
41 .BR sched_setscheduler ()
43 sets both the scheduling policy and parameters for the
44 thread whose ID is specified in \fIpid\fP.
45 If \fIpid\fP equals zero, the
46 scheduling policy and parameters of the calling thread will be set.
48 The scheduling parameters are specified in the
50 argument, which is a pointer to a structure of the following form:
62 In the current implementation, the structure contains only one field,
66 depends on the selected policy.
68 Currently, Linux supports the following "normal"
69 (i.e., non-real-time) scheduling policies as values that may be specified in
73 the standard round-robin time-sharing policy;
74 .\" In the 2.6 kernel sources, SCHED_OTHER is actually called
78 for "batch" style execution of processes; and
83 low priority background jobs.
85 For each of the above policies,
86 .IR param\->sched_priority
89 Various "real-time" policies are also supported,
90 for special time-critical applications that need precise control over
91 the way in which runnable threads are selected for execution.
92 For the rules governing when a process may use these policies, see
94 The real-time policies that may be specified in
99 a first-in, first-out policy; and
102 a round-robin policy.
104 For each of the above policies,
105 .IR param\->sched_priority
106 specifies a scheduling priority for the thread.
107 This is a number in the range returned by calling
108 .BR sched_get_priority_min (2)
110 .BR sched_get_priority_max (2)
113 On Linux, these system calls return, respectively, 1 and 99.
115 Since Linux 2.6.32, the
116 .B SCHED_RESET_ON_FORK
120 .BR sched_setscheduler ().
121 As a result of including this flag, children created by
123 do not inherit privileged scheduling policies.
128 .BR sched_getscheduler ()
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.
135 .BR sched_setscheduler ()
138 .BR sched_getscheduler ()
139 returns the policy for the thread (a nonnegative integer).
140 On error, both calls return \-1, and
142 is set appropriately.
153 .RB ( sched_setscheduler ())
155 is not one of the recognized policies.
158 .RB ( sched_setscheduler ())
160 does not make sense for the specified
164 The calling thread does not have appropriate privileges.
167 The thread whose ID is \fIpid\fP could not be found.
169 POSIX.1-2001, POSIX.1-2008 (but see BUGS below).
170 The \fBSCHED_BATCH\fP and \fBSCHED_IDLE\fP policies are Linux-specific.
172 Further details of the semantics of all of the above "normal"
173 and "real-time" scheduling policies can be found in the
176 That page also describes an additional policy,
178 which is settable only via
179 .BR sched_setattr (2).
181 POSIX systems on which
182 .BR sched_setscheduler ()
184 .BR sched_getscheduler ()
186 .B _POSIX_PRIORITY_SCHEDULING
189 POSIX.1 does not detail the permissions that an unprivileged
190 thread requires in order to call
191 .BR sched_setscheduler (),
192 and details vary across systems.
193 For example, the Solaris 7 manual page says that
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.
197 The scheduling policy and parameters are in fact per-thread
199 The value returned from a call to
201 can be passed in the argument
205 as 0 will operate on the attributes of the calling thread,
206 and passing the value returned from a call to
208 will operate on the attributes of the main thread of the thread group.
209 (If you are using the POSIX threads API, then use
210 .BR pthread_setschedparam (3),
211 .BR pthread_getschedparam (3),
213 .BR pthread_setschedprio (3),
218 POSIX.1 says that on success,
219 .BR sched_setscheduler ()
220 should return the previous scheduling policy.
222 .BR sched_setscheduler ()
223 does not conform to this requirement,
224 since it always returns 0 on success.
230 .BR sched_get_priority_max (2),
231 .BR sched_get_priority_min (2),
232 .BR sched_getaffinity (2),
233 .BR sched_getattr (2),
234 .BR sched_getparam (2),
235 .BR sched_rr_get_interval (2),
236 .BR sched_setaffinity (2),
237 .BR sched_setattr (2),
238 .BR sched_setparam (2),
241 .BR capabilities (7),