通过之前的学习我知道了当前 Linux 系统下任务调度策略主要有三种:
1、SCHED_OTHER:普通任务调度策略。
2、SCHED_FIFO:实时任务调度策略,先到先服务。一旦占用cpu则一直运行,直到有更高优先级任务到达或自己放弃。
3、SCHED_RR:实时任务调度策略,时间片轮转。当任务的时间片用完,系统将重新分配时间片,并置于就绪队列尾。放在队列尾
保证了所有具有相同优先级的RR任务的调度公平。
Linux 提供的有关任务调度策略及优先级的接口函数:
1、
// 首先了解 sched_param 结构体// In the current implementation, the structure contains only one field, sched_priority. // The interpretation of param depends on the selected policystruct sched_param {
int sched_priority;};
int sched_setscheduler(pid_t pid, int policy, const struct sched_param *param);int sched_getscheduler(pid_t pid);
The sched_setscheduler() system call sets both the scheduling policy and parameters for the thread whose ID is specified in pid.
If pid equals zero, the scheduling policy and parameters of the calling thread will be set.
The sched_getscheduler() returns the current scheduling policy of the thread identified by pid. If pid equals zero, the policy of the
calling thread will be retrieved.
与上面函数类似的还有:
int sched_setparam(pid_t pid, const struct sched_param *param);int sched_getparam(pid_t pid, struct sched_param *param);
我们可以使