如何修改主线程的调度策略
我现在想要将主线程的调度策略从默认的SCHED_OTHER修改为SCHED_RR,根据查阅的资料来看应该是调用pthread_setschedparam这个函数,但是我调用的时候要么没有设置成功,要么就是Invalid argument。我确定我是用root用户编译以及运行的程序,所以不能够理解,希望能够有人为我解答,谢谢。
代码如下:
#include <stdio.h>#include <pthread.h>#include <sched.h>main(){ struct sched_param param; int policy; if (pthread_getschedparam(pthread_self(), &policy, ¶m) != 0) perror("pthread_getschedparam:"); printf("sched_priority:%d\n", param.sched_priority); if (pthread_setschedparam(pthread_self(), SCHED_FIFO, ¶m) != 0) perror("pthread_setschedparam:"); if (pthread_getschedparam(pthread_self(), &policy, ¶m) != 0) perror("pthread_getschedparam:"); if (policy == SCHED_RR) printf("policy is SCHED_RR\n"); else if (policy == SCHED_OTHER) printf("policy is SCHED_OTHER\n"); else if (policy == SCHED_FIFO) printf("policy is SCHED_FIFO\n"); else printf("policy is %d\n", policy); while (1) { printf("In while (1)\n"); sleep(5); } return 0;}