taskset 为程序指定cpu核心

来源:互联网 发布:我们相爱吧网络直播 编辑:程序博客网 时间:2024/06/09 23:21

确定核心数

cat /proc/cpuinfo

 

查看程序所使用的核心

 

taskset -p $pid

 

例如:

[root@M /]# taskset -p 27693
pid 27693's current affinity mask: 69

 

mask为16进制

0x00000069
二进制之后1101001

所以pid 27693运行在0 3 6 7 核心上

 

       0x00000001
              is processor #0

       0x00000003(二进制 00000011)
              is processors #0 and #1

       0xFFFFFFFF
              is all processors (#0 through #31)

 

 

查看多进程的时候可以使用:


 

 

 

 

 

SYNOPSIS
       taskset [options] [mask | list ] [pid | command [arg]...]
OPTIONS
       -p, --pid
              operate on an existing PID and not launch a new task
       -c, --cpu-list
              specifiy a numerical list of processors instead of a bitmask.
              The list may contain multiple items, separated by comma, and
              ranges. For example, 0,5,7,9-11.
       -h, --help
              display usage information and exit
       -V, --version
              output version information and exit

taskset -cp 1 27693   #调整已经存在的进程(pid 27693)到cpu1上

taskset -c 0-3 /usr/local/nginx/sbin/nginx start #重新开启一个nginx进程在0~3的核心上。

 

原创粉丝点击