2

我可以使用“taskset -c 0 ./out”从终端执行此操作。我怎样才能从 Eclipse 做同样的事情?

4

2 回答 2

1

尝试这个

/* 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();
于 2014-01-27T17:26:19.840 回答
0

运行 -> 运行配置 -> 参数(选项卡)

添加

/C "tasket -c 0 .\out"

于 2020-09-06T10:27:20.430 回答