Sched_idle在Sched_setscheduler()中无效

发布于 2025-01-20 07:57:43 字数 1052 浏览 3 评论 0原文

当我运行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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文