<分区>
Possible Duplicate:
CPU Affinity
在运行 Linux (fc12) 的 x86 机器上,我可以让一个进程在多处理器系统的特定内核上运行吗?我知道有一个函数 sched_setaffinity
可以帮助选择处理器,但我想在处理器的特定核心上执行该过程。
<分区>
Possible Duplicate:
CPU Affinity
在运行 Linux (fc12) 的 x86 机器上,我可以让一个进程在多处理器系统的特定内核上运行吗?我知道有一个函数 sched_setaffinity
可以帮助选择处理器,但我想在处理器的特定核心上执行该过程。
最佳答案
不确定这是否是您需要的,我使用这段代码使线程在特定核心上运行。 使用 -pthread 编译和链接。
#include "pthread.h"
#include "sched.h"
int affinity = 3; //core id
pthread_t mythread;
mythread = pthread_self();
cpu_set_t cpuset;
CPU_ZERO(&cpuset);
CPU_SET(affinity, &cpuset); //lets kernel know only core affinity may run this thread
if (pthread_setaffinity_np(mythread, sizeof(cpu_set_t), &cpuset) <0){
perror("sched_set_affinity");
}
关于linux - 在处理器的特定核心上运行进程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12197222/