1SCHED_SETSCHEDULER(2)      Linux Programmer's Manual     SCHED_SETSCHEDULER(2)
2
3
4

NAME

6       sched_setscheduler,  sched_getscheduler  -  set and get scheduling pol‐
7       icy/parameters
8

SYNOPSIS

10       #include <sched.h>
11
12       int sched_setscheduler(pid_t pid, int policy,
13                              const struct sched_param *param);
14
15       int sched_getscheduler(pid_t pid);
16

DESCRIPTION

18       The sched_setscheduler() system call sets both  the  scheduling  policy
19       and  parameters  for  the  thread whose ID is specified in pid.  If pid
20       equals zero, the scheduling policy and parameters of the calling thread
21       will be set.
22
23       The scheduling parameters are specified in the param argument, which is
24       a pointer to a structure of the following form:
25
26           struct sched_param {
27               ...
28               int sched_priority;
29               ...
30           };
31
32       In the current implementation, the structure contains only  one  field,
33       sched_priority.   The  interpretation  of param depends on the selected
34       policy.
35
36       Currently, Linux supports the following "normal" (i.e.,  non-real-time)
37       scheduling policies as values that may be specified in policy:
38
39       SCHED_OTHER   the standard round-robin time-sharing policy;
40
41       SCHED_BATCH   for "batch" style execution of processes; and
42
43       SCHED_IDLE    for running very low priority background jobs.
44
45       For each of the above policies, param->sched_priority must be 0.
46
47       Various "real-time" policies are also supported, for special time-crit‐
48       ical applications that need precise  control  over  the  way  in  which
49       runnable  threads  are selected for execution.  For the rules governing
50       when a process may use these policies,  see  sched(7).   The  real-time
51       policies that may be specified in policy are:
52
53       SCHED_FIFO    a first-in, first-out policy; and
54
55       SCHED_RR      a round-robin policy.
56
57       For  each  of  the  above  policies,  param->sched_priority specifies a
58       scheduling priority for the thread.  This is  a  number  in  the  range
59       returned  by  calling  sched_get_priority_min(2)  and  sched_get_prior‐
60       ity_max(2) with the specified policy.  On  Linux,  these  system  calls
61       return, respectively, 1 and 99.
62
63       Since  Linux 2.6.32, the SCHED_RESET_ON_FORK flag can be ORed in policy
64       when calling sched_setscheduler().  As a result of including this flag,
65       children  created by fork(2) do not inherit privileged scheduling poli‐
66       cies.  See sched(7) for details.
67
68       sched_getscheduler() returns  the  current  scheduling  policy  of  the
69       thread  identified by pid.  If pid equals zero, the policy of the call‐
70       ing thread will be retrieved.
71

RETURN VALUE

73       On   success,   sched_setscheduler()   returns   zero.    On   success,
74       sched_getscheduler()  returns  the policy for the thread (a nonnegative
75       integer).  On error, both calls return -1, and errno is  set  appropri‐
76       ately.
77

ERRORS

79       EINVAL Invalid arguments: pid is negative or param is NULL.
80
81       EINVAL (sched_setscheduler()) policy is not one of the recognized poli‐
82              cies.
83
84       EINVAL (sched_setscheduler()) param does not make sense for the  speci‐
85              fied policy.
86
87       EPERM  The calling thread does not have appropriate privileges.
88
89       ESRCH  The thread whose ID is pid could not be found.
90

CONFORMING TO

92       POSIX.1-2001,  POSIX.1-2008  (but see BUGS below).  The SCHED_BATCH and
93       SCHED_IDLE policies are Linux-specific.
94

NOTES

96       Further details of the semantics of  all  of  the  above  "normal"  and
97       "real-time"  scheduling  policies  can  be found in the sched(7) manual
98       page.  That page also describes an additional  policy,  SCHED_DEADLINE,
99       which is settable only via sched_setattr(2).
100
101       POSIX  systems  on  which sched_setscheduler() and sched_getscheduler()
102       are available define _POSIX_PRIORITY_SCHEDULING in <unistd.h>.
103
104       POSIX.1 does not detail the permissions  that  an  unprivileged  thread
105       requires in order to call sched_setscheduler(), and details vary across
106       systems.  For example, the Solaris 7 manual page says that the real  or
107       effective user ID of the caller must match the real user ID or the save
108       set-user-ID of the target.
109
110       The scheduling policy and parameters are in fact per-thread  attributes
111       on Linux.  The value returned from a call to gettid(2) can be passed in
112       the argument pid.  Specifying pid as 0 will operate on  the  attributes
113       of  the  calling  thread, and passing the value returned from a call to
114       getpid(2) will operate on the attributes of  the  main  thread  of  the
115       thread  group.   (If  you  are  using  the  POSIX threads API, then use
116       pthread_setschedparam(3),         pthread_getschedparam(3),         and
117       pthread_setschedprio(3), instead of the sched_*(2) system calls.)
118

BUGS

120       POSIX.1  says  that  on success, sched_setscheduler() should return the
121       previous scheduling policy.  Linux sched_setscheduler() does  not  con‐
122       form to this requirement, since it always returns 0 on success.
123

SEE ALSO

125       chrt(1), nice(2), sched_get_priority_max(2), sched_get_priority_min(2),
126       sched_getaffinity(2), sched_getattr(2), sched_getparam(2),
127       sched_rr_get_interval(2), sched_setaffinity(2), sched_setattr(2),
128       sched_setparam(2), sched_yield(2), setpriority(2), capabilities(7),
129       cpuset(7), sched(7)
130

COLOPHON

132       This  page  is  part of release 5.04 of the Linux man-pages project.  A
133       description of the project, information about reporting bugs,  and  the
134       latest     version     of     this    page,    can    be    found    at
135       https://www.kernel.org/doc/man-pages/.
136
137
138
139Linux                             2017-09-15             SCHED_SETSCHEDULER(2)
Impressum