CentOS下如何查看多核负载?CentOS下查看多核负载的方法

2020-01-30 15:55:06于丽

1. Linux下,如何看每个CPU的使用率:

#top -M

之后按下数字1. (或者top之后按1也一样)则显示多个CPU 的信息,和内存信息:

[root@testpc ~]# top -M

top - 15:38:40 up 2 days,  2:05,  2 users,  load average: 0.00, 0.00, 0.00

Tasks: 138 total,   1 running, 137 sleeping,   0 stopped,   0 zombie

Cpu0  :  0.0%us,  0.0%sy,  0.0%ni,100.0%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st

Cpu1  :  0.0%us,  0.0%sy,  0.0%ni,100.0%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st

Cpu2  :  0.0%us,  0.0%sy,  0.0%ni,100.0%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st

Cpu3  :  0.0%us,  0.0%sy,  0.0%ni,100.0%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st

Mem:  3725.047M total,  263.312M used, 3461.734M free,   45.711M buffers

Swap: 8095.992M total,    0.000k used, 8095.992M free,   55.977M cached

PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND                                                                        

    1 root      20   0 19228 1512 1224 S  0.0  0.0   0:00.61 init                                                                            

    2 root      20   0     0    0    0 S  0.0  0.0   0:00.00 kthreadd  

2. 在Linux下,如何确认是多核或多CPU:

#cat /proc/cpuinfo

如果有多个类似以下的项目,则为多核或多CPU:

processor       : 0

......

processor       : 1

3. 如何察看某个进程在哪个CPU上运行:

#top -d 1

之后按下f.进入top Current Fields设置页面:

选中:j: P          = Last used cpu (SMP)

则多了一项:P 显示此进程使用哪个CPU。

Sam经过试验发现:同一个进程,在不同时刻,会使用不同CPU Core.这应该是Linux Kernel SMP处理的。