Sched_idle在Sched_setscheduler()中无效
当我运行chrt -m
时,我会看到不同的策略类型:
SCHED_OTHER min/max priority : 0/0
SCHED_FIFO min/max priority : 1/99
SCHED_RR min/max priority : 1/99
SCHED_BATCH min/max priority : 0/0
SCHED_IDLE min/max priority : 0/0
SCHED_DEADLINE min/max priority : 0/0
但是,当我使用sched_setscheduler(pid_num,sched_idle,& sp);
在C代码中时,我得到以下错误:
error: ‘SCHED_IDLE’ undeclared (first use in this function); did you mean ‘SCHED_RR’?
如何解决该问题?
示例代码如下所示
#include <unistd.h>
#include <sched.h>
#include <stdio.h>
int main()
{
int pid_num = getpid();
struct sched_param sp = { .sched_priority = 99 };
int ret = sched_setscheduler(pid_num, SCHED_IDLE, &sp);
printf("\n");
return 0;
}
系统信息如下所示:
$ uname -r
5.13.0-27-generic
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 20.04.3 LTS
Release: 20.04
Codename: focal
When I run chrt -m
, I see different policy types:
SCHED_OTHER min/max priority : 0/0
SCHED_FIFO min/max priority : 1/99
SCHED_RR min/max priority : 1/99
SCHED_BATCH min/max priority : 0/0
SCHED_IDLE min/max priority : 0/0
SCHED_DEADLINE min/max priority : 0/0
However, when I use sched_setscheduler(pid_num, SCHED_IDLE, &sp);
in the C code, I get the following error:
error: ‘SCHED_IDLE’ undeclared (first use in this function); did you mean ‘SCHED_RR’?
Any idea on how to fix that?
A sample code is shown below
#include <unistd.h>
#include <sched.h>
#include <stdio.h>
int main()
{
int pid_num = getpid();
struct sched_param sp = { .sched_priority = 99 };
int ret = sched_setscheduler(pid_num, SCHED_IDLE, &sp);
printf("\n");
return 0;
}
System information is shown below:
$ uname -r
5.13.0-27-generic
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 20.04.3 LTS
Release: 20.04
Codename: focal
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论