确定核心数
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的核心上。
通过`taskset`命令,可以查看或设置进程使用的CPU核心。例如,PID为27693的进程运行在0、3、6、7核心上。使用`-p`选项操作现有PID,`-c`选项指定处理器列表。要启动新进程在特定核心上,如`taskset -c 0-3 nginx start`。


被折叠的 条评论
为什么被折叠?



