Linux如何查看CPU信息,Linux查看CPU個數和核心數,Linux查看CPU使用率和運行位數

Linux如何查看CPU信息,Linux查看CPU個數和核心數,Linux查看CPU使用率和運行位數

2017年11月24日 11:52:17 tiiefu1212 閱讀數 14584es6

api

1、Linux查看CPU基本信息,能夠使用命令:安全

cat /proc/cpuinfoflex

例如筆者的虛擬機:ui

[root@promote ~]# cat /proc/cpuinfo
processor : 0
vendor_id : GenuineIntel
cpu family : 6
model : 37
model name : Intel(R) Core(TM) i5 CPU M 520 @ 2.40GHz
stepping : 5
cpu MHz : 2394.049
cache size : 3072 KB
fpu : yes
fpu_exception : yes
cpuid level : 11
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts mmx fxsr sse sse2 ss syscall nx rdtscp lm constant_tsc up arch_perfmon pebs bts xtopology tsc_reliable nonstop_tsc aperfmperf unfair_spinlock pni pclmulqdq ssse3 cx16 sse4_1 sse4_2 x2apic popcnt aes hypervisor lahf_lm ida arat dts
bogomips : 4788.09
clflush size : 64
cache_alignment : 64
address sizes : 40 bits physical, 48 bits virtual
power management:spa

可見,筆者這臺虛擬機,有一個邏輯CPU,主頻是2.4。.net

延伸:code

processor 邏輯處理器的id。
physical id 物理封裝的處理器的id。
core id 每一個核心的id。
cpu cores 位於相同物理封裝的處理器中的內核數量。
siblings 位於相同物理封裝的處理器中的邏輯處理器的數量。blog

2、如何查看CPU邏輯個數排序

方法1:

cat /proc/cpuinfo

processor : 11
vendor_id : GenuineIntel
cpu family : 6
model : 62
model name : Intel(R) Xeon(R) CPU E5-2620 v2 @ 2.10GHz
stepping : 4
microcode : 1064
cpu MHz : 2100.170
cache size : 15360 KB
physical id : 0
siblings : 12
core id : 5
cpu cores : 6
apicid : 11
initial apicid : 11
fpu : yes
fpu_exception : yes
cpuid level : 13
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good xtopology nonstop_tsc aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm ida arat xsaveopt pln pts dts tpr_shadow vnmi flexpriority ept vpid fsgsbase smep erms
bogomips : 4200.34
clflush size : 64
cache_alignment : 64
address sizes : 46 bits physical, 48 bits virtual
power management:

能夠看出有12個邏輯CPU。由於processor從0開始,到11結束,說明有12個。

方法2:

cat /proc/cpuinfo | grep name | cut -f2 -d: | uniq -c

例如,

[root@localhost ~]# cat /proc/cpuinfo | grep name | cut -f2 -d: | uniq -c

     12  Intel(R) Xeon(R) CPU E5-2620 v2 @ 2.10GHz

能夠看到有12個邏輯CPU。

方法3:

cat /proc/cpuinfo | grep physical | uniq -c

例如,

[root@localhost ~]# cat /proc/cpuinfo | grep physical | uniq -c
1 physical id : 0
1 address sizes : 46 bits physical, 48 bits virtual
1 physical id : 0
1 address sizes : 46 bits physical, 48 bits virtual
1 physical id : 0
1 address sizes : 46 bits physical, 48 bits virtual
1 physical id : 0
1 address sizes : 46 bits physical, 48 bits virtual
1 physical id : 0
1 address sizes : 46 bits physical, 48 bits virtual
1 physical id : 0
1 address sizes : 46 bits physical, 48 bits virtual
1 physical id : 0
1 address sizes : 46 bits physical, 48 bits virtual
1 physical id : 0
1 address sizes : 46 bits physical, 48 bits virtual
1 physical id : 0
1 address sizes : 46 bits physical, 48 bits virtual
1 physical id : 0
1 address sizes : 46 bits physical, 48 bits virtual
1 physical id : 0
1 address sizes : 46 bits physical, 48 bits virtual
1 physical id : 0
1 address sizes : 46 bits physical, 48 bits virtual

也能看出來是12個,不過須要數一下。

更簡單的方法還有:

(1)、cat /proc/cpuinfo |grep "processor"|wc -l

[root@localhost ~]# cat /proc/cpuinfo |grep "processor"|wc -l

12

直接計算出來是12,都不用數了。

(2)、cat /proc/cpuinfo |grep "physical id"

[root@localhost ~]# cat /proc/cpuinfo |grep "physical id"

physical id : 0

physical id : 0

physical id : 0

physical id : 0

physical id : 0

physical id : 0

physical id : 0

physical id : 0

physical id : 0

physical id : 0

physical id : 0

physical id : 0

這個須要數一下才能知道是12。

(3)、cat /proc/cpuinfo |grep "processor"

[root@localhost ~]# cat /proc/cpuinfo |grep "processor"

processor : 0

processor : 1

processor : 2

processor : 3

processor : 4

processor : 5

processor : 6

processor : 7

processor : 8

processor : 9

processor : 10

processor : 11

這個法子不錯,直接按處理器排序到11。一眼看出來是12。

3、如何查看每一個CPU核心數。

有個簡單的命令:

cat /proc/cpuinfo |grep "cores"

[root@localhost ~]# cat /proc/cpuinfo |grep "cores"

cpu cores : 6

cpu cores : 6

cpu cores : 6

cpu cores : 6

cpu cores : 6

cpu cores : 6

cpu cores : 6

cpu cores : 6

cpu cores : 6

cpu cores : 6

cpu cores : 6

cpu cores : 6

能夠看到,12個邏輯CPU中,每一個CPU都是6核。

其實在查看CPU基本信息裏,有個cpu cores:6,直接就顯示是6個。

4、查看CPU使用率的命令

top

延伸:

使用權限:全部使用者

使用方式:top [-] [d delay] [q] [c] [S] [s] [i] [n] [b]

說明:即時顯示process的動態

d :改變顯示的更新速度,或是在交談式指令列( interactive command)按s

q :沒有任何延遲的顯示速度,若是使用者是有superuser的權限,則top將會以最高的優先序執行

c :切換顯示模式,共有兩種模式,一是隻顯示執行檔的名稱,另外一種是顯示完整的路徑與名稱S :累積模式,會將己完成或消失的子行程( dead child process )的CPU time累積起來

s :安全模式,將交談式指令取消,避免潛在的危機

i :不顯示任何閒置(idle)或無用(zombie)的行程

n :更新的次數,完成後將會退出top

b :批次檔模式,搭配"n"參數一塊兒使用,能夠用來將top的結果輸出到檔案內

例如,

Linux的TOP命令查看CPU使用率

能夠看到CPU使用率百分比。Ctrl+C能夠退出TOP。 

也能夠使用命令:cat /proc/stat查看。例如:

[root@localhost ~]# cat /proc/stat
cpu 27115520 242 4622815 4662722506 12504018 246 96658 0 0
cpu0 4126112 0 855568 375445053 10489170 76 32126 0 0
cpu1 2370590 0 291429 389439543 27264 53 6368 0 0
cpu2 1744553 0 225295 390309511 16425 12 3430 0 0
cpu3 1451736 0 256399 390612263 9784 1 3077 0 0
cpu4 911835 0 257589 391264891 7095 0 2000 0 0
cpu5 706379 0 249467 391522706 5312 0 1582 0 0
cpu6 11307712 0 976287 378460372 1915138 0 14559 0 0
cpu7 1069543 0 354557 390922711 9657 0 8219 0 0
cpu8 827844 0 269726 391350780 5797 5 7072 0 0
cpu9 1043103 242 351579 390805163 7193 21 8010 0 0
cpu10 884193 0 298011 391092737 6363 30 6141 0 0
cpu11 671915 0 236902 391496772 4814 45 4067 0 0
intr 3434565703 127 0 0 1 1 0 0 0 1 116 247 0 0 0 0 0 0 0 0 0 0 0 138 113 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 13094 0 0 0 0 0 0 0 0 0 0 0 0 0 75734895 117 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 56232283 21536519 17473625 17213052 17575845 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0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469303
btime 1426551690
processes 7425277
procs_running 2
procs_blocked 0
softirq 1862968701 0 592789560 785619 277080030 72116042 0 72554297 243093245 7677488 596872420

能夠看到12個CPU使用的狀況。

5、查看CPU運行在多少位下的命令

getconf LONG_BIT

[root@localhost ~]# getconf LONG_BIT
64
[root@localhost ~]#

能夠看到運行在64位下。

6、查看CPU是否支持64位運算

cat /proc/cpuinfo | grep flags | grep ' lm '|wc -l

[root@localhost ~]# cat /proc/cpuinfo | grep flags | grep ' lm '|wc -l
12
[root@localhost ~]#

等於12,說明12個邏輯CPU都支持64位運算, lm指long mode, 支持lm則是64bit。

相關文章
相關標籤/搜索