现在的位置: 首页 > 综合 > 正文

CPU利用率==如何看每个CPU的使用率

2019年05月04日 ⁄ 综合 ⁄ 共 693字 ⁄ 字号 评论关闭

 gcc -o uu uu.c -lpthread -D_GNU_SOURCE

ret = 000

if(ret !=o)

{

kkllkl

}

【如何看每个CPU的使用率】

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

#top -d 1

之后按下数字1. 则显示多个CPU   (top后按1也一样)

Cpu0  :  1.0%us,  3.0%sy,  0.0%ni, 96.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

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处理的。

4. 配置Linux Kernel使之支持多Core:

内核配置期间必须启用 CONFIG_SMP 选项,以使内核感知 SMP。

Processor type and features  ---> Symmetric multi-processing support

察看当前Linux Kernel是否支持(或者使用)SMP

#uname -a

抱歉!评论已关闭.