sched_setscheduler(2) sched_setscheduler(2)
sched_setscheduler - set the scheduling policy of a process
#include <sched.h>
int sched_setscheduler (pid_t pid<b>, int policy<b>,
const struct sched_param *param<b>);
The sched_setscheduler system call is used to set the scheduling policy
and related parameters for the process specified by pid. If pid is set
to zero, then the scheduling policy and parameters of the calling process
will be affected.
The policy parameter is used to select one of the following scheduling
policies:
SCHED_FIFO [Toc] [Back]
The first-in-first-out policy schedules processes according to
their assigned priority values. The highest priority process is
guaranteed control of the processor until it willingly yields the
processor or blocks on a contended resource. If there is more
than one runnable highest priority process, the highest priority
process waiting the longest is granted control of the processor.
A running process is preempted when a higher priority process
becomes runnable.
SCHED_RR [Toc] [Back]
The round-robin scheduling policy schedules processes according
to their assigned priority values. The highest priority process
is guaranteed control of the processor until it: willingly yields
the processor, blocks on a contended resource, or exceeds its
time quantum. If there is more than one runnable highest priority
process, the highest priority process waiting the longest is
granted control of the processor. When a process exceeds its time
quantum it yields the processor and awaits rescheduling. A
running process is preempted when a higher priority process
becomes runnable.
Note that SCHED_FIFO and SCHED_RR processes are of higher priority than
all other processes in the system. Because of this, such a process may
deadlock the system if it enters an infinite loop. Further note, that
the scheduling policy and priority are inherited across a fork and that
the scheduling policy is shared by all members of a share group (see
sproc(2)).
SCHED_TS [Toc] [Back]
The SCHED_TS scheduling policy is a basic timeshare scheduling
policy. All SCHED_TS processes acquire CPU resources in
proportion to their priority or nice value. Processes aquire the
processor for a time quantum, the length of which is returned via
the sched_rr_get_interval(2) system call.
Page 1
sched_setscheduler(2) sched_setscheduler(2)
SCHED_OTHER [Toc] [Back]
The SCHED_OTHER scheduling policy is equivalent to the SCHED_TS
policy and allows a program to indicate that it no longer needs a
real-time scheduling policy in a portable manner.
The parameters of the selected policy are specified by the parameter
structure at address param.
The priority of the target process may be modified by setting the desired
priority value in the sched_priority field of the param structure.
Unlike IRIX 6.2 and previous releases, processes having a higher
numerical priority value are more important than processes having a lower
numerical priority value. Specified priorities remain fixed, unless
explicitly changed in the future, and are not affected by priority aging
schemes.
The priority range for these scheduling policies may be obtained via the
sched_get_priority_min(2) and sched_get_priority_max(2) function calls.
However, arbitrary priority values should not be used. Developers must
consider the needs of the application and how it should interact with the
rest of the system, before selecting a real-time priority. For more
information, see the "Real-Time Priority Band" section of realtime(5).
Runnable processes scheduled with real-time policies are always granted
processor control ahead of timeshare processes, regardless of priority.
The calling process must have the CAP_SCHED_MGT capability [see
capability] to successfully execute sched_setscheduler.
If the process specified by pid is currently executing or is in a
runnable state, sched_setscheduler causes the process to be rescheduled
in accordance with its priority.
sched_setscheduler will fail if one or more of the following are true:
[EINVAL] The policy argument does not represent a valid posix
scheduling policy.
[EINVAL] One of the specified parameters at address param are out
of range or scope.
[EPERM] The calling process does not have the CAP_SCHED_MGT
capability.
[ESRCH] The process specified by pid does not exist.
capability(4), realtime(5), sched_getparam(2), sched_setparam(2),
sched_getscheduler(2), sched_yield(2), sched_get_priority_max(2),
sched_get_priority_min(2), sched_rr_get_interval(2), pthreads(5)
Page 2
sched_setscheduler(2) sched_setscheduler(2)
Upon successful completion, sched_setscheduler returns the previous
scheduling policy value of the process pid.
Upon failure, a value of -1 is returned to the calling process and errno
is set to indicate the error.
PPPPaaaaggggeeee 3333 [ Back ]
|