c - 在 Ubuntu 中从 Eclipse 运行 C 代码时如何设置 CPU 亲和性?

标签 c eclipse ubuntu affinity

我可以使用“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/

相关文章:

c - 求一个内核宏: hlist_nulls_for_each_entry的解释

c - Z_MEM_ERROR Zlib deflateInit2() 嵌入式设备

python - 在 pydev 中调试 - 如何使 python 对象可扩展 - 就像在 java 调试器中一样?

linux - 使用 Systemd 在 Ubuntu VM 的后台运行 Node 应用程序

python - Theano GPU 内存不足错误

linux - 如何在 linux ubuntu 上安装 flatc 和 flatbuffers

c - zlib 压缩和解压使用

c - c如何处理不同范围内的相同变量名?

Eclipse PDE : What is a "target platform"?

android - 如何使每个 ListItem 转到不同的 Activity