Node:Basic Scheduling Functions, Next:Traditional Scheduling, Previous:Realtime Scheduling, Up:Priority
This section describes functions in the GNU C library for setting the absolute priority and scheduling policy of a process.
Portability Note: On systems that have the functions in this
section, the macro _POSIX_PRIORITY_SCHEDULING is defined in
<unistd.h>
.
For the case that the scheduling policy is traditional scheduling, more functions to fine tune the scheduling are in Traditional Scheduling.
Don't try to make too much out of the naming and structure of these functions. They don't match the concepts described in this manual because the functions are as defined by POSIX.1b, but the implementation on systems that use the GNU C library is the inverse of what the POSIX structure contemplates. The POSIX scheme assumes that the primary scheduling parameter is the scheduling policy and that the priority value, if any, is a parameter of the scheduling policy. In the implementation, though, the priority value is king and the scheduling policy, if anything, only fine tunes the effect of that priority.
The symbols in this section are declared by including file sched.h
.
struct sched_param | Data Type |
This structure describes an absolute priority.
|
int sched_setscheduler (pid_t pid, int policy, const struct sched_param *param) | Function |
This function sets both the absolute priority and the scheduling policy for a process. It assigns the absolute priority value given by param and the
scheduling policy policy to the process with Process ID pid,
or the calling process if pid is zero. If policy is
negative, The following macros represent the valid values for policy:
On success, the return value is
|
int sched_getscheduler (pid_t pid) | Function |
This function returns the scheduling policy assigned to the process with Process ID (pid) pid, or the calling process if pid is zero. The return value is the scheduling policy. See
If the function fails, the return value is instead The
Note that this function is not an exact mate to |
int sched_setparam (pid_t pid, const struct sched_param *param) | Function |
This function sets a process' absolute priority. It is functionally identical to |
int sched_getparam (pid_t pid, const struct sched_param *param) | Function |
This function returns a process' absolute priority. pid is the Process ID (pid) of the process whose absolute priority you want to know. param is a pointer to a structure in which the function stores the absolute priority of the process. On success, the return value is
|
int sched_get_priority_min (int *policy); | Function |
This function returns the lowest absolute priority value that is allowable for a process with scheduling policy policy. On Linux, it is 0 for SCHED_OTHER and 1 for everything else. On success, the return value is
|
int sched_get_priority_max (int *policy); | Function |
This function returns the highest absolute priority value that is allowable for a process that with scheduling policy policy. On Linux, it is 0 for SCHED_OTHER and 99 for everything else. On success, the return value is
|
int sched_rr_get_interval (pid_t pid, struct timespec *interval) | Function |
This function returns the length of the quantum (time slice) used with the Round Robin scheduling policy, if it is used, for the process with Process ID pid. It returns the length of time as interval. With a Linux kernel, the round robin time slice is always 150 microseconds, and pid need not even be a real pid. The return value is |
int sched_yield (void) | Function |
This function voluntarily gives up the process' claim on the CPU. Technically, If there are no other processes that share the calling process' absolute priority, this function doesn't have any effect. To the extent that the containing program is oblivious to what other processes in the system are doing and how fast it executes, this function appears as a no-op. The return value is |