linux下设置进程调度策略
#include <stdlib.h> /* exit */ #include <stdio.h> /* printf */ #include <sched.h> /* sched_**** */
int main(int argc, char *argv[]) { printf ("Policy %d\n", sched_getscheduler(0)); printf("max priority: %d\n", sched_get_priority_max(0)); /* 99 for real-time process 0 non-real-time process */ struct sched_param param; int maxFIFO; int maxRR; maxFIFO = sched_get_priority_max(SCHED_FIFO); maxRR = sched_get_priority_max(SCHED_RR); if(maxFIFO == -1 || maxRR == -1){ perror("sched_get_priority_max() error!\n"); exit(1); } param.sched_priority = maxFIFO; if(sched_setscheduler(getpid(), SCHED_FIFO, ¶m) == -1){ perror("sched_setscheduler() error!\n"); exit(1); } printf ("Policy %d\n", sched_getscheduler(0)); param.sched_priority = maxRR; if(sched_setscheduler(getpid(), SCHED_RR, ¶m) == -1){ perror("sched_setscheduler() error!\n"); exit(1); } printf ("Policy %d\n", sched_getscheduler(0));
return 0; }
最后执行a.out时必须具有su权限。
sched_normal 或者 sched_other是Linux默认的调度策略,其值为0
sched_fifo 为1
sched_rr 为2

浙公网安备 33010602011771号