我正在尝试:
与处理器固定同时运行 16 个副本(每个内核 2 个副本)
与处理器固定(每个内核 2 个副本)并发运行 8 个副本,并在某些功能说功能 1 完成后将处理器内核翻转到最远的内核。
我面临的问题是如何选择最远的处理器。
有 friend 建议用sched_getaffinity和sched_setaffinity,但我估计没找到什么好的例子。
最佳答案
要使用 sched_setaffinity 使当前进程在核心 7 上运行,您可以这样做:
cpu_set_t my_set; /* Define your cpu_set bit mask. */
CPU_ZERO(&my_set); /* Initialize it all to 0, i.e. no CPUs selected. */
CPU_SET(7, &my_set); /* set the bit that represents core 7. */
sched_setaffinity(0, sizeof(cpu_set_t), &my_set); /* Set affinity of tihs process to */
/* the defined mask, i.e. only 7. */
见 http://linux.die.net/man/2/sched_setaffinity & http://www.gnu.org/software/libc/manual/html_node/CPU-Affinity.html了解更多信息。
关于c - 如何从 C 在 Linux 中使用 sched_getaffinity 和 sched_setaffinity?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10490756/