 |
» |
|
|
 |
NAMErtsched: sched_get_priority_max(), sched_get_priority_min(), sched_getparam(), sched_getscheduler(), sched_rr_get_interval(), sched_setparam(), sched_setscheduler(), sched_yield(), PRI_HPUX_TO_POSIX(), PRI_POSIX_TO_HPUX() — real-time scheduling operations SYNOPSIS#include <sched.h>
int sched_setparam(
pid_t pid,
const struct sched_param *param
);
int sched_getparam(
pid_t pid,
struct sched_param *param
);
int sched_setscheduler(
pid_t pid,
int policy,
const struct sched_param *param
);
int sched_getscheduler(
pid_t pid
);
int sched_yield();
int sched_get_priority_max(
int policy
);
int sched_get_priority_min(
int policy
);
int sched_rr_get_interval(
pid_t pid,
struct timespec *interval
);
int PRI_POSIX_TO_HPUX(
int pri
);
int PRI_HPUX_TO_POSIX(
int pri
); DESCRIPTIONSummary- sched_get_priority_max()
Get maximum scheduling policy - sched_get_priority_min()
Get minimum scheduling policy - sched_getparam()
Get scheduling parameters of process - sched_getscheduler()
Get scheduling policy of process - sched_rr_get_interval()
Update execution time limit for a process - sched_setparam()
Set scheduling parameters of process - sched_setscheduler()
Set scheduling policy and parameters of process - sched_yield()
Requeue current process in process list - PRI_HPUX_TO_POSIX()
Convert HP-UX priority to POSIX - PRI_POSIX_TO_HPUX()
Convert POSIX priority to HP-UX
sched_setparam()The
sched_setparam()
function sets the scheduling parameters of the process specified by
pid
to the values specified by the
sched_param
structure pointed to by
param.
The value of the
sched_priority
member in the
param
structure is any integer within the inclusive priority range
for the current scheduling policy of the process specified by
pid. Higher numerical values for the priority
represent higher (stronger) priorities.
Note that this is different from the
SCHED_HPUX,
SCHED_TIMESHARE,
SCHED_NOAGE,
and
SCHED_RTPRIO
scheduling policies,
where higher numerical values represent lower (weaker) priorities.
See the
PRI_HPUX_TO_POSIX()
and
PRI_POSIX_TO_HPUX()
functions, and
SCHED_RTPRIO,
SCHED_NOAGE,
and
SCHED_OTHER
in "Scheduling Policies" below. If a process described by
pid
exists and if the calling process has permission,
the scheduling parameters
are set for the process whose process ID is equal to
pid. If
pid
is zero, the scheduling parameters are set for the calling process. If the process
pid
contains more than one thread or lightweight process (that is, the process
is multithreaded), this function will affect the policy and priority of
individual kernel schedulable entities in the process depending on their
scheduling contention scope.
For threads created with system contention scope, this system call will
have no effect on their scheduling or the scheduling of the underlying
kernel scheduled entities. For threads with process contention scope, the threads' scheduling parameters
will not be affected. However, the underlying kernel scheduled entities
for the process contention scope threads will have their scheduling
parameters changed to the value specified in param.
Kernel scheduled entities for use by process contention scope threads that
are created after this call completes, inherit their scheduling policy and
associated scheduling parameters from the process.
The priority returned is the old priority of the target process, though
individual threads or lightweight processes may have a different value if
some other interface is used to change an individual thread or
lightweight processes priority. Only a superuser may change the scheduling parameters of another process. The calling process must have the appropriate privileges
or be a member of a group having
PRIV_RTSCHED
access to successfully call
sched_setparam(). The target process, whether it is running or not running,
will resume execution after all other runnable processes
of equal or greater priority have been scheduled to run. If the priority of the process specified by the
pid
argument is set higher than that of the lowest priority running process,
and if the specified process is ready to run, the process specified by the
pid
argument will preempt a lowest-priority running process.
Similarly, if the process calling
sched_setparam()
sets its own priority lower than
that of one or more other nonempty process lists,
then the process that is the head of the highest priority list
will also preempt the calling process.
Thus, in either case, the originating process may not receive notification
of the completion of the requested priority change
until the higher priority process has executed. sched_getparam()The
sched_getparam()
function returns the scheduling parameters of a process specified by
pid
in the
sched_param
structure pointed to by
param. If a process described by
pid
exists,
the scheduling parameters are returned for the process
whose process ID is equal to
pid. If the process
pid
contains more than one thread or lightweight process (that is, the process is
multithreaded), this function shall only return the process scheduling
policy and priority.
Individual threads or lightweight processes in the target process will have
their own scheduling policies and priorities which may be different from the
scheduling policy and priority of their process. If
pid
is zero, the scheduling parameters are returned for the calling process. sched_setscheduler()The
sched_setscheduler()
function sets the scheduling policy and
scheduling parameters of the process
specified by
pid
to
policy
and the parameters specified in the
sched_param
structure pointed to by
param,
respectively.
The value of the
sched_priority
member in the
param
structure can be any integer within the inclusive priority range
for the scheduling policy specified by
policy. The possible values for the
policy
parameter are defined in the header file
<sched.h>,
and mentioned below. If a process described by
pid
exists,
the scheduling policy and scheduling parameters
are set for the process whose process ID is equal to
pid. If
pid
is zero, the scheduling policy and scheduling parameters
are set for the calling process. If the process
pid
contains more than one thread or lightweight process (that is, the process
is multithreaded), this function will affect the policy and priority of
individual kernel schedulable entities in the process dependening on their
scheduling contention scope.
For threads created with system contention scope, this system call will
have no effect on their scheduling or the scheduling of the underlying
kernel scheduled entities. For threads with process contention scope, the threads' scheduling parameters
will not be affected. However, the underlying kernel scheduled entities
for the process contention scope threads will have their scheduling
parameters changed to the value specified in param.
Kernel scheduled entities for use by process contention scope threads that
are created after this call completes, inherit their scheduling policy and
associated scheduling parameters from the process.
The priority returned is the old priority of the target process, though
an individual thread or lightweight process may have a different value if
some other interface is used to change individual thread's or lightweight
process's priority. Appropriate privileges are required
to change the scheduling parameters of another process. The calling process must have appropriate privileges
or be a member of a group having
PRIV_RTSCHED
access to successfully call
sched_setscheduler(). The
sched_setscheduler()
function is considered successful if it succeeds
in setting the scheduling policy and scheduling parameters
of the process specified by
pid
to the values specified by
policy
and the structure
param,
respectively. sched_getscheduler()The
sched_getscheduler()
function returns the scheduling policy of the process specified by
pid. The values that can be returned by
sched_getscheduler()
are defined in the header file
<sched.h>
(see
sched_setscheduler()). If a process described by
pid
exists, the scheduling policy
is returned for the process whose process ID is equal to
pid. If
pid
is zero, the scheduling policy is returned for the calling process. If the process
pid
contains more than one thread or lightweight process (that is, the process is
multithreaded), this function shall only return the process scheduling
policy and priority.
Individual threads or lightweight processes in the target process will have
their own scheduling policies and priorities which may be different from the
scheduling policy and priority of their process. sched_yield()The
sched_yield()
function forces the running process to relinquish the processor
until it again becomes the head of its process list.
It takes no arguments. sched_get_priority_min()The
sched_get_priority_max()
and
sched_get_priority_min()
functions return the appropriate maximum or minimum,
respectively, for the
scheduling policy specified by
policy. The value of
policy
must be one of the scheduling policy values defined in
<sched.h>. sched_rr_get_interval()The
sched_rr_get_interval()
function updates the
timespec
structure referenced by the
interval
argument to contain the current execution time limit
(that is, time quantum)
for the process indicated by
pid
under the
SCHED_RR
policy, at which a scheduling decision will be made
when another process at the same priority is ready to execute.
If
pid
is zero, the current execution time limit for the
calling process is returned. PRI_POSIX_TO_HPUX()These two functions serve to map (translate)
the range of HP-UX priorities into the POSIX.4 model.
These translations are necessary because the POSIX.4 standard chose
larger
numbers to represent stronger priorities and the existing HP-UX behavior,
which must be maintained for backward compatibility, uses
smaller
numbers for stronger priorities. The
PRI_HPUX_TO_POSIX()
function returns the POSIX.4 scheduling priority corresponding to the HP-UX
priority passed in the argument
pri.
The value of
pri
can be any integer. The
PRI_POSIX_TO_HPUX()
function returns an HP-UX process priority corresponding to the
priority passed in the argument
pri.
The value of
pri
can be any integer.
The HP-UX priority returned is comparable to the values returned by
getpriority()
(see
getpriority(2)). Scheduling PoliciesThe scheduling policies described are defined in terms
of a conceptual model,
which contains a set of process lists.
There is, conceptually, one process list for each priority.
Any runnable process may be in any process list.
Multiple scheduling policies are provided.
Each nonempty list is ordered,
and contains a head as one end of its order, and a tail as the other.
The purpose of a scheduling policy is to define the allowable operations
on this set of lists
(for example, moving processes between and within lists). Each process will be controlled
by an associated scheduling policy and priority.
These parameters may be specified by explicit application execution of the
sched_setscheduler()
or
sched_setparam()
functions. Associated with each policy is a priority range.
The priority ranges for each policy
can (but need not) overlap the priority ranges of other policies. When a process is to be selected to run,
the process that is at the head
of the highest priority nonempty process list is chosen.
It is then removed from its process list. The following scheduling policies are defined:
- SCHED_FIFO
First in-first out (FIFO) scheduling policy. Processes scheduled under this policy are chosen
from a process list that is ordered
by the time its processes have been in the list without being executed.
Generally, the head of the list is the process
that has been in the list the longest time,
and the tail is the process that has been in the list the shortest time. Under the
SCHED_FIFO
policy, the modification of the definitional process lists
is as follows:
When a running process becomes a preempted process,
it becomes the head of the process list for its priority. When a blocked process becomes a runnable process,
it becomes the tail of the process list for its priority. When a running process calls the
sched_setscheduler()
function,
the process specified in the function call
is modified to the policy and priority specified by the
param
argument.
If the process whose policy and priority has been modified
is a running process or is runnable,
it then becomes the tail of the process list for its new priority. When a running process calls the
sched_setparam()
function,
the priority of the process specified in the function call
is modified to the priority specified by the
param
argument.
If the process whose priority has been modified
is a running process or is runnable,
it then becomes the tail of the process list for its new priority. When a running process issues the
sched_yield()
function, the process becomes the tail of the process list for its priority. At no other time is the position of a process with this scheduling
policy within the process lists affected.
For this policy,
valid priorities are within the range returned by the functions
sched_get_priority_max()
and
sched_get_priority_min()
when
SCHED_FIFO
is provided as the parameter.
The priority range for this policy contains at least 32 priorities. - SCHED_RR
Round-robin scheduling policy, with a per-system time slice (time quantum). This policy is identical to the
SCHED_FIFO
policy with the additional condition that when the implementation detects
that a running process has been executing as a running process
for a time period of length returned by the function
sched_rr_get_interval(),
or longer, the process becomes the tail of its process list,
and the head of that process list is removed and made a running process. The effect of this policy is to ensure that if there are multiple
SCHED_RR
processes at the same priority,
one of them will not monopolize the processor.
An application should not rely only on the use of
SCHED_RR
to ensure application progress among multiple processes
if the application includes processes using the
SCHED_FIFO
policy at the same or higher priority levels, or
SCHED_RR
processes at a higher priority level. A process under this policy that is preempted
and subsequently resumes execution as a running process
completes the unexpired portion of its round-robin interval time period. For this policy, valid priorities are within the range
returned by the functions
sched_get_priority_max()
and
sched_get_priority_min()
when
SCHED_RR
is provided as the parameter.
The priority range for this policy contains at least 32 priorities. - SCHED_RR2
Round-robin scheduling policy, with a per-priority time slice (time quantum). This policy is identical to the
SCHED_RR
policy, except that the round-robin time slice interval returned by
sched_rr_get_interval()
depends upon the priority of the specified process. For this policy, valid priorities are within the range
returned by the functions
sched_get_priority_max()
and
sched_get_priority_min()
when
SCHED_RR
is provided as the parameter.
The priority range for this policy contains at least 32 priorities. - SCHED_RTPRIO
Real-time scheduling policy with nondecaying priorities (like
SCHED_FIFO
and
SCHED_RR)
with a priority range between the POSIX real-time policies
and the HP-UX policies, described below (see
rtprio(2)). For processes executing under this policy,
the implementation must use only
priorities within the range returned by the functions
sched_get_priority_max()
and
sched_get_priority_min()
when
SCHED_RTPRIO
is provided as the parameter.
Note that, for the
SCHED_RTPRIO
scheduling policy,
smaller
numbers represent higher (stronger) priorities,
which is the opposite of the POSIX scheduling policies.
This is done to provide continuing support
for existing applications that depend on this priority ordering.
However, it is guaranteed that the priority range for the
SCHED_OTHER
scheduling policy is properly disjoint
from the priority ranges of all of the
other scheduling policies described and the strongest priority in the
priority range for
SCHED_RTPRIO
is weaker than the weakest priority in the priority ranges for any of
the POSIX policies,
SCHED_FIFO,
SCHED_RR,
and
SCHED_RR2. - SCHED_OTHER (SCHED_HPUX, SCHED_TIMESHARE)
Another scheduling policy. The
SCHED_OTHER
policy, also known as
SCHED_HPUX
and
SCHED_TIMESHARE,
provides a way for applications to indicate, in a portable way,
that they no longer need a real-time scheduling policy. For processes executing under this policy,
the implementation can use only priorities within the range
returned by the functions
sched_get_priority_max()
and
sched_get_priority_min()
when
SCHED_OTHER
is provided as the parameter.
Note that for the
SCHED_OTHER
scheduling policy, like
SCHED_RTPRIO,
smaller
numbers represent higher (stronger) priorities,
which is the opposite of the POSIX scheduling policies.
This is done to provide continuing support
for existing applications that depend on this priority ordering.
However, it is guaranteed that the priority range for the
SCHED_OTHER
scheduling policy is properly disjoint
from the priority ranges of all of the real-time
scheduling policies described and the strongest priority in the
priority range for
SCHED_OTHER
is weaker than the weakest priority in the priority ranges for any of
the other policies,
SCHED_FIFO,
SCHED_RR,
and
SCHED_RR2. - SCHED_NOAGE
A timeshare scheduling policy with nondecaying priorities. For processes executing under this policy,
the implementation can use only priorities within the range
returned by the functions
sched_get_priority_max()
and
sched_get_priority_min()
when
SCHED_NOAGE
is provided as the parameter. The priority range for the
SCHED_NOAGE
policy is a subset of the priority range supported by the
SCHED_TIMESHARE
policy.
Note that for the
SCHED_NOAGE
scheduling policy,
smaller
numbers represent higher (stronger) priorities,
which is the opposite of the POSIX scheduling policies. The priority value of a process executing with the
SCHED_NOAGE
policy is not decayed or boosted by the operating system scheduler. For
SCHED_TIMESHARE
policy, the priority value of the process is decayed as the process consumes
processor cycles and boosted when the process waits for processor cycles.
The threads in different processor sets do not compete with one another
for processors based on their scheduling policy and priority values.
The scheduler looks only at threads assigned to a processor's processor
set to choose the next thread to run. A process with lower scheduling
priority in one processor set may be executing while another process in
another processor set with higher scheduling priority is waiting for the
processor resources. This is applicable for all scheduling policies. RETURN VALUEThe functions return the following values: sched_yield()- 0
Successful completion. - -1
Failure.
errno
is set to indicate the error.
sched_setscheduler()- n
Successful completion.
n
is the former scheduling policy of the specified process. - -1
Failure.
The policy and scheduling parameters remain unchanged.
errno
is set to indicate the error.
sched_getscheduler()- n
Successful completion.
n
is the scheduling policy of the specified process. - -1
Failure.
errno
is set to indicate the error.
sched_get_priority_min()- n
Successful completion.
n
is the maximum or minimum value, respectively. - -1
Failure.
errno
is set to indicate the error.
PRI_HPUX_TO_POSIX()- n
Successful completion.
n
is the the POSIX.4 priority corresponding to
pri.
PRI_POSIX_TO_HPUX()- n
Successful completion.
n
is the the HP-UX priority corresponding to
pri.
ERRORSIf the functions fail,
errno
is set to one of the following values. sched_setparam()- [EFAULT]
The
param
argument points to an invalid address. - [EINVAL]
One or more of the requested scheduling parameters is outside the range
defined for the scheduling policy of the specified
pid. - [ENOSYS]
The function is not supported by this implementation. - [EPERM]
The requesting process does not have permission to set the scheduling
parameters for the specified process, or does not have the appropriate
privilege to invoke
sched_setparam(). - [ESRCH]
No process can be found corresponding to that specified by
pid.
sched_getparam()- [EFAULT]
The
param
argument points to an invalid address. - [ENOSYS]
The function is not supported by this implementation. - [ESRCH]
No process can be found corresponding to that specified by
pid.
sched_setscheduler()- [EFAULT]
The
param
argument points to an invalid address. - [EINVAL]
The value of the
policy
parameter is invalid, or one or more of the parameters contained in
param
is outside the valid range for the specified scheduling policy. - [ENOSYS]
The function is not supported by this implementation. - [EPERM]
The requesting process does not have permission to set the
scheduling policy of the specified process. - [ESRCH]
No process can be found corresponding to that specified by
pid.
sched_getscheduler()- [ENOSYS]
The function is not supported by this implementation. - [ESRCH]
No process can be found corresponding to that specified by
pid.
sched_yield()- [ENOSYS]
The function is not supported by this implementation.
sched_get_priority_min()- [EINVAL]
The value of the
policy
parameter does not represent a defined scheduling policy. - [ENOSYS]
The function is not supported by this implementation.
sched_rr_get_interval()- [ENOSYS]
The function is not supported by this implementation. - [ESRCH]
No process can be found corresponding to that specified by
pid.
EXAMPLESChange the calling process to use the strongest
FIFO
priority:
#include <sched.h>
struct sched_param param;
int maxpri;
maxpri = sched_get_priority_max(SCHED_FIFO);
if (maxpri == -1) {
perror("sched_get_priority_max() failed");
exit(1);
}
param.sched_priority = maxpri;
if (sched_setscheduler(getpid(), SCHED_FIFO, ¶m) == -1) {
perror("sched_setscheduler() failed");
exit(1);
} AUTHORThe
sched_*()
functions
were derived from the proposed IEEE POSIX P1003.4 standard, draft 14. PRI_HPUX_TO_POSIX()
and
PRI_POSIX_TO_HPUX()
were developed by HP. STANDARDS CONFORMANCEsched_get_priority_max(): POSIX.4 sched_get_priority_min(): POSIX.4 sched_getparam(): POSIX.4 sched_getscheduler(): POSIX.4 sched_rr_getinterval(): POSIX.4 sched_setparam(): POSIX.4 sched_setscheduler(): POSIX.4 sched_yield(): POSIX.4
|