setting cpu affinity of a process from the start on linux

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-30 23:11:59

问题


I want to set the cpu affinity of a process on linux when it is starting.

There are methods like sched_setaffinity and taskset, but they need the processid of the process. They may cause potential migration like a process was started on a core but after the use of sched_setaffinity/taskset, they were migrated to another core.

What I want to do is to start a new process on a specific core from the beginning.


回答1:


taskset can be used both to set the affinity of a running process or to launch a process with a certain affinity, see

  • How to launch your application in a specific CPU in Linux (CPU affinity)?.
  • man page for taskset

Synopsis

taskset [options] mask command [arg]...
taskset [options] -p [mask] pid

The below command will launch Google Chrome browser in CPU 1 & 2 (or 0 and 1). The mask is 0×00000003 and command is “google-chrome”.

taskset 0×00000003 google-chrome


来源:https://stackoverflow.com/questions/15451049/setting-cpu-affinity-of-a-process-from-the-start-on-linux

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!