获取当前进程ID
ps -aux | grep "cpu_processor_test"
查看该进程在哪些cpu运行
root@localhost:~# taskset -p 4181
pid 4181's current affinity mask: f
f转换为2进制为1111,说明进程在4个核心上运行。
设置进程在cpu1上运行
[root@localhost ~]# taskset -pc 1 5904
pid 5904's current affinity list: 0-7
pid 5904's new affinity list: 1
cpu编号为0-7,这里将程序设置在了cpu1上运行
确认绑定情况
[root@localhost ~]# taskset -p 5904
pid 5904's current affinity mask: 2
显示的数字2转换2进制为10,表示在第二个cpu上运行,即为cpu1。
启动程序时绑定cpu
taskset -c 2 ./cpu_processor_test&
[1] 1615
ppid 1439 pid 1615