Copyright (C) 2000-2012 |
GNU Info (libc.info)Basic Scheduling FunctionsBasic Scheduling Functions -------------------------- 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 Note: 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'. - Data Type: struct sched_param This structure describes an absolute priority. `int sched_priority' absolute priority value - Function: int sched_setscheduler (pid_t PID, int POLICY, const struct sched_param *PARAM) 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, `sched_setscheduler' keeps the existing scheduling policy. The following macros represent the valid values for POLICY: `SCHED_OTHER' Traditional Scheduling `SCHED_FIFO' First In First Out `SCHED_RR' Round Robin On success, the return value is `0'. Otherwise, it is `-1' and `ERRNO' is set accordingly. The `errno' values specific to this function are: `EPERM' * The calling process does not have `CAP_SYS_NICE' permission and POLICY is not `SCHED_OTHER' (or it's negative and the existing policy is not `SCHED_OTHER'. * The calling process does not have `CAP_SYS_NICE' permission and its owner is not the target process' owner. I.e. the effective uid of the calling process is neither the effective nor the real uid of process PID. `ESRCH' There is no process with pid PID and PID is not zero. `EINVAL' * POLICY does not identify an existing scheduling policy. * The absolute priority value identified by *PARAM is outside the valid range for the scheduling policy POLICY (or the existing scheduling policy if POLICY is negative) or PARAM is null. `sched_get_priority_max' and `sched_get_priority_min' tell you what the valid range is. * PID is negative. - Function: int sched_getscheduler (pid_t PID) 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 `sched_setscheduler' for the possible values. If the function fails, the return value is instead `-1' and `errno' is set accordingly. The `errno' values specific to this function are: `ESRCH' There is no process with pid PID and it is not zero. `EINVAL' PID is negative. Note that this function is not an exact mate to `sched_setscheduler' because while that function sets the scheduling policy and the absolute priority, this function gets only the scheduling policy. To get the absolute priority, use `sched_getparam'. - Function: int sched_setparam (pid_t PID, const struct sched_param *PARAM) This function sets a process' absolute priority. It is functionally identical to `sched_setscheduler' with POLICY = `-1'. - Function: int sched_getparam (pid_t PID, const struct sched_param *PARAM) 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 `0'. Otherwise, it is `-1' and `ERRNO' is set accordingly. The `errno' values specific to this function are: `ESRCH' There is no process with pid PID and it is not zero. `EINVAL' PID is negative. - Function: int sched_get_priority_min (int *POLICY); 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 `0'. Otherwise, it is `-1' and `ERRNO' is set accordingly. The `errno' values specific to this function are: `EINVAL' POLICY does not identify an existing scheduling policy. - Function: int sched_get_priority_max (int *POLICY); 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 `0'. Otherwise, it is `-1' and `ERRNO' is set accordingly. The `errno' values specific to this function are: `EINVAL' POLICY does not identify an existing scheduling policy. - Function: int sched_rr_get_interval (pid_t PID, struct timespec *INTERVAL) 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 `0' on success and in the pathological case that it fails, the return value is `-1' and `errno' is set accordingly. There is nothing specific that can go wrong with this function, so there are no specific `errno' values. - Function: int sched_yield (void) This function voluntarily gives up the process' claim on the CPU. Technically, `sched_yield' causes the calling process to be made immediately ready to run (as opposed to running, which is what it was before). This means that if it has absolute priority higher than 0, it gets pushed onto the tail of the queue of processes that share its absolute priority and are ready to run, and it will run again when its turn next arrives. If its absolute priority is 0, it is more complicated, but still has the effect of yielding the CPU to other processes. 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 `0' on success and in the pathological case that it fails, the return value is `-1' and `errno' is set accordingly. There is nothing specific that can go wrong with this function, so there are no specific `errno' values. automatically generated by info2www version 1.2.2.9 |