您的位置:首页 > 其它

将进程绑定到特定的cpu - taskset命令

2017-10-12 09:57 309 查看
在测试斗地主程序的时候,发现单核cpu的运行时间总比多核cpu运行时间块,用taskset命令一看,果然是一个进程运行在两个cpu上。

Score of team 1 is : -1154
Score of team 2 is : 148
Score of team 3 is : 1006

real 4m12.768s
user 0m12.307s
sys      0m2.703s

[root@ying ~]# ps -aux | grep dou
root     30958 18.0  0.4  15508  4112 pts/0    S+   09:14   0:00 ./doudizhu_platform
root     30960  0.0  0.0   9028   660 pts/1    R+   09:14   0:00 grep --color=auto dou
[root@ying ~]# taskset -p 30958
pid 30958's current affinity mask: 1


Score of team 1 is : -1100
Score of team 2 is : 568
Score of team 3 is : 532

real      6m41.709s
user  0m7.428s
sys   0m2.776s

root@10.63.93.13:~# ps -aux | grep dou
root      2314  2.5  0.9 177940 161356 pts/1   S+   09:06   0:09 ./doudizhu_platform
root     26076  0.0  0.0  12180   704 pts/2    S+   09:13   0:00 grep --color=auto dou
root@10.63.93.13:~# taskset -p 2314
pid 2314's current affinity mask: ff
root@10.63.93.13:~# taskset -p 2314
pid 2314's current affinity mask: ff


最后在将一个进程固定到cpu上貌似没啥效果,么有找到原因。不知道和单核机器和多核机器的gcc版本有没有关系

Score of team 1 is : -182
Score of team 2 is : 97
Score of team 3 is : 85

real        6m44.039s
user    0m7.668s
sys     0m2.568s

root@10.63.93.13:~# ps -aux | grep dou
root     16842  2.3  0.0  19628  2988 pts/1    S+   09:29   0:00 ./doudizhu_platform
root     22093  0.0  0.0  12176   704 pts/2    S+   09:29   0:00 grep --color=auto dou
root@10.63.93.13:~# taskset -pc 0 16842
pid 16842's current affinity list: 0-7
pid 16842's new affinity list: 0
root@10.63.93.13:~# taskset -p 16842
pid 16842's current affinity mask: 1
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: