【问题标题】:Using the C programming language, what is the best way to make a multicore RedHat Linux processor, use only one core in a test application?使用 C 编程语言,使多核 RedHat Linux 处理器在测试应用程序中仅使用一个内核的最佳方法是什么?
【发布时间】:2013-09-23 02:59:42
【问题描述】:

使用 C 编程语言,制作多核 Red Hat Linux 处理器的最佳方法是什么,在测试应用程序中只使用一个内核?

【问题讨论】:

    标签: c


    【解决方案1】:

    有一个专门用于此目的的Linux system call,称为sched_setaffinity

    对于example,在 CPU 0 上运行:

    #include <sched.h>
    int main(void)
    {
        cpu_set_t  mask;
        CPU_ZERO(&mask);
        CPU_SET(0, &mask);
        result = sched_setaffinity(0, sizeof(mask), &mask);
        return 0;
    }
    

    【讨论】:

    • @Gearoid Murphy,谢谢你的回答。我会测试一小时并奖励你一个 Stack Overflow 积分并接受你的回答。
    • 注:int main(void)
    猜你喜欢
    • 1970-01-01
    • 2010-10-01
    • 2017-04-08
    • 2019-06-14
    • 1970-01-01
    • 2011-03-26
    • 1970-01-01
    • 2016-09-28
    • 2010-09-29
    相关资源
    最近更新 更多