千家信息网

利用taskset命令,将某进程绑定到某个CPU上

发表于:2025-01-31 作者:千家信息网编辑
千家信息网最后更新 2025年01月31日,taskset (util-linux-ng 2.17.2)usage: taskset [options] [mask | cpu-list] [pid | cmd [args...]]set or
千家信息网最后更新 2025年01月31日利用taskset命令,将某进程绑定到某个CPU上
taskset (util-linux-ng 2.17.2)usage: taskset [options] [mask | cpu-list] [pid | cmd [args...]]set or get the affinity of a process  -p, --pid                  operate on existing given pid  -c, --cpu-list             display and specify cpus in list format  -h, --help                 display this help  -V, --version              output version informationThe default behavior is to run a new command:  taskset 03 sshd -b 1024You can retrieve the mask of an existing task:  taskset -p 700Or set it:  taskset -p 03 700List format uses a comma-separated list instead of a mask:  taskset -pc 0,3,7-11 700Ranges in list format can take a stride argument:  e.g. 0-31:2 is equivalent to mask 0x55555555

例:

将pid号为2181的进程绑定到cpu0上:

[root@Centos ~]# taskset -cp 0 2181pid 2181's current affinity list: 0pid 2181's new affinity list: 0

将pid号为2181的进程绑定到几个cpu上:

[root@Centos ~]# taskset -cp 0,1 2181  --绑定到cpu0和cpu1上


0