【Linux命令017】查看CPU个数与型号

Scroll Down

cat /proc/cpuinfo

常用命令如下:

# 查看cpu详细信息
cat /proc/cpuinfo

# 查看CPU信息(型号)
cat /proc/cpuinfo | grep name | cut -f2 -d: | uniq -c

# 查看物理CPU个数
cat /proc/cpuinfo| grep "physical id"| sort| uniq| wc -l

# 查看每个物理CPU中core的个数(即核数)
cat /proc/cpuinfo| grep "cpu cores"| uniq

# 查看逻辑CPU的个数
cat /proc/cpuinfo| grep "processor"| wc -l

下面是我阿里云的服务器信息,2核4G的ECS。

[root@iZ2zebthf35ejlps5v87ksZ ~]# cat /proc/cpuinfo | grep name | cut -f2 -d: | uniq -c
  2  Intel(R) Xeon(R) CPU E5-2682 v4 @ 2.50GHz
[root@iZ2zebthf35ejlps5v87ksZ ~]# cat /proc/cpuinfo| grep "physical id"| sort| uniq| wc -l
1
[root@iZ2zebthf35ejlps5v87ksZ ~]# cat /proc/cpuinfo| grep "cpu cores"| uniq
cpu cores	: 1
[root@iZ2zebthf35ejlps5v87ksZ ~]# cat /proc/cpuinfo| grep "processor"| wc -l
2

从上面的结果可以看到,我的机器拥有两个逻辑cpu,型号是Intel(R) Xeon(R) CPU E5-2682 v4 @ 2.50GHz,但是从结果“physical”来看,只有一个物理核心。

扩展:uniq命令是去重,wc是统计。

lscpu

此外,还有个lscpu命令,可以提供有效、精简的cpu信息。

实例如下:

[root@yaomm ~]# lscpu
Architecture:          x86_64   
CPU op-mode(s):        32-bit, 64-bit
Byte Order:            Little Endian
CPU(s):                2      
On-line CPU(s) list:   0,1
Thread(s) per core:    2
Core(s) per socket:    1
Socket(s):             1
NUMA node(s):          1
Vendor ID:             GenuineIntel
CPU family:            6
Model:                 79
Model name:            Intel(R) Xeon(R) CPU E5-2682 v4 @ 2.50GHz
Stepping:              1
CPU MHz:               2500.030
BogoMIPS:              5000.06
Hypervisor vendor:     KVM     
Virtualization type:   full
L1d cache:             32K     
L1i cache:             32K
L2 cache:              256K
L3 cache:              40960K
NUMA node0 CPU(s):     0,1
Flags:                 fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc rep_good nopl eagerfpu pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch ibrs ibpb stibp fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm rdseed adx smap xsaveopt spec_ctrl intel_stibp

部分参数释义如下

  • Architecture: x86_64 #<=== x86架构
  • CPU(s): 2 #<=== 双核cpu
  • Thread(s) per core: 2 #<=== 每核超线程
  • Core(s) per socket: 1 #<=== 每核线程数
  • Socket(s): 1 #<=== 主板插槽,物理cpu数
  • Model name: Intel(R) Xeon(R) CPU E5-2682 v4 @ 2.50GHz #<=== cpu型号
  • L1d cache 及其他cache #<=== cpu缓存相关