从一开始就在Linux上设置进程的cpu亲和力 [英] setting cpu affinity of a process from the start on linux
问题描述
我想在启动时在Linux上设置进程的cpu亲和力.
I want to set the cpu affinity of a process on linux when it is starting.
有诸如sched_setaffinity和taskset之类的方法,但是它们需要进程的processid.它们可能会导致潜在的迁移,就像在核心上启动进程一样,但是在使用sched_setaffinity/taskset之后,它们已迁移到另一个核心.
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.
推荐答案
taskset
既可以用于设置正在运行的进程的亲和力,也可以用于启动具有一定亲和力的进程,请参见
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
简介
taskset [options] mask command [arg]...
taskset [options] -p [mask] pid
以下命令将在CPU 1&中启动Google Chrome浏览器. 2(或0和1).掩码为0×00000003,命令为"google-chrome".
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
这篇关于从一开始就在Linux上设置进程的cpu亲和力的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!