Process 无法使用sched_setscheduler()函数设置调度策略?

Process 无法使用sched_setscheduler()函数设置调度策略?,process,operating-system,scheduling,job-scheduling,Process,Operating System,Scheduling,Job Scheduling,我是操作系统编程新手。因此,我编写这段代码是为了更改后台进程的调度策略,我通过命令行参数提供其进程ID,但sched_setscheduler()函数失败,并给出一个错误“function not implemented” #包括 #包括 #包括 int main(int argc,char*argv[]){ 结构sched_param param; 参数sched_优先级=80; int-pid=atoi(argv[1]); int policy=sched_getscheduler(pid)

我是操作系统编程新手。因此,我编写这段代码是为了更改后台进程的调度策略,我通过命令行参数提供其进程ID,但sched_setscheduler()函数失败,并给出一个错误“function not implemented”

#包括
#包括
#包括
int main(int argc,char*argv[]){
结构sched_param param;
参数sched_优先级=80;
int-pid=atoi(argv[1]);
int policy=sched_getscheduler(pid);
printf(“当前策略:%d\n”,策略);
if(调度设置调度程序(pid、调度FIFO和参数)=-1){
perror(“无法设置计划程序策略”);
}
int new_policy=sched_getscheduler(pid);
printf(“新策略:%d\n”,新策略);
}
有人能告诉我为什么会这样吗?谢谢

因此,我编写这段代码是为了更改后台进程的调度策略,我通过命令行参数提供其进程ID

问题就在这里。获取线程id而不是进程id。对于单线程进程
PID
TID
重合,但在多线程进程中,每个线程都有自己的
TID

参数名为
pid
且类型为
pid\t
这一事实可能会产生误导,甚至
sched\u setscheduler(2)
的一些旧手册页错误地谈论进程,但该函数实际上是关于线程的

#include <sched.h>
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char* argv[]){
    struct sched_param param;
    param.sched_priority = 80;
    int pid = atoi(argv[1]);
    int policy = sched_getscheduler(pid);
    printf("Current policy: %d\n", policy);
    if(sched_setscheduler(pid, SCHED_FIFO, &param) == -1){
        perror("Scheduler policy cannot be set");
    }
    int new_policy = sched_getscheduler(pid);
    printf("New policy: %d\n", new_policy);
}