我可以使用“taskset -c 0 ./out”从终端执行此操作。 我如何从 Eclipse 中执行相同的操作?
最佳答案
试试这个
/* must be root to use these sched_function-----------------------*/
#define CPU_N 0 // affinity process
void fix_affinity()
{
int error=0;
cpu_set_t mask;
/* mask init */
CPU_ZERO(&mask);
/* add CPU_N to the mask */
CPU_SET(CPU_N,&mask);
/**
test root access
**/
if(getuid()==0)
{
/*change affinity of process */
error=sched_setaffinity(0,sizeof(cpu_set_t),&mask);
}
else
{
printf("must be root to change affinity\n");
}
if(error<0)
{
printf("sched_setaffinity() failed \n");
}
}
然后在你的代码中调用它
fix_affinity();
关于c - 在 Ubuntu 中从 Eclipse 运行 C 代码时如何设置 CPU 亲和性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15036725/