一直没有注意到的死角,linux有几个系统调用跟调度策略有关
sched_get_priority_max 取得静态优先级的上限
sched_get_priority_min 取得静态优先级的下限
sched_getparam 取得进程的调度参数
sched_getscheduler 取得指定进程的调度策略
sched_rr_get_interval 取得按RR算法调度的实时进程的时间片长度
sched_setparam 设置进程的调度参数
sched_setscheduler 设置指定进程的调度策略和参数
sched_yield 进程主动让出处理器,并将自己等候调度队列队尾
//范例程序 注意当进程变成实时进程时非常霸道,要是此时进入死循环会让你很难受的
#include <sched.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
int main()
{
int rc,old_scheduler_policy;
struct sched_param my_params;
old_scheduler_policy=sched_getscheduler(0);
my_params.sched_priority=sched_get_priority_max(SCHED_RR);// 尽可能高的实时优先级
printf("SCHED_OTHER = %d SCHED_FIFO =%d SCHED_RR=%d \n",SCHED_OTHER,SCHED_FIFO,SCHED_RR);
printf("the current scheduler = %d \n",old_scheduler_policy);
printf("press any key to change the current scheduler and priority to SCHED_RR\n");
getchar();
rc=sched_setscheduler(0,SCHED_RR,&my_params);
if(rc<0)
{
perror("sched_setscheduler to SCHED_RR error");
exit(0);
}
old_scheduler_policy=sched_getscheduler(0);
printf("the current scheduler = %d \n",old_scheduler_policy);
printf("press any key to change the current scheduler and priority to SCHED_FIFO\n");
getchar();
rc=sched_setscheduler(0,SCHED_FIFO,&my_params);
if(rc<0)
{
perror("sched_setscheduler to SCHED_FIFO error");
exit(0);
}
old_scheduler_policy=sched_getscheduler(0);
printf("the current scheduler = %d \n",old_scheduler_policy);
printf("press any key to exit\n");
getchar();
return 0;
}
sched_get_priority_max 取得静态优先级的上限
sched_get_priority_min 取得静态优先级的下限
sched_getparam 取得进程的调度参数
sched_getscheduler 取得指定进程的调度策略
sched_rr_get_interval 取得按RR算法调度的实时进程的时间片长度
sched_setparam 设置进程的调度参数
sched_setscheduler 设置指定进程的调度策略和参数
sched_yield 进程主动让出处理器,并将自己等候调度队列队尾
//范例程序 注意当进程变成实时进程时非常霸道,要是此时进入死循环会让你很难受的
#include <sched.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
int main()
{
int rc,old_scheduler_policy;
struct sched_param my_params;
old_scheduler_policy=sched_getscheduler(0);
my_params.sched_priority=sched_get_priority_max(SCHED_RR);// 尽可能高的实时优先级
printf("SCHED_OTHER = %d SCHED_FIFO =%d SCHED_RR=%d \n",SCHED_OTHER,SCHED_FIFO,SCHED_RR);
printf("the current scheduler = %d \n",old_scheduler_policy);
printf("press any key to change the current scheduler and priority to SCHED_RR\n");
getchar();
rc=sched_setscheduler(0,SCHED_RR,&my_params);
if(rc<0)
{
perror("sched_setscheduler to SCHED_RR error");
exit(0);
}
old_scheduler_policy=sched_getscheduler(0);
printf("the current scheduler = %d \n",old_scheduler_policy);
printf("press any key to change the current scheduler and priority to SCHED_FIFO\n");
getchar();
rc=sched_setscheduler(0,SCHED_FIFO,&my_params);
if(rc<0)
{
perror("sched_setscheduler to SCHED_FIFO error");
exit(0);
}
old_scheduler_policy=sched_getscheduler(0);
printf("the current scheduler = %d \n",old_scheduler_policy);
printf("press any key to exit\n");
getchar();
return 0;
}