怎样在Linux上查看CPU相关的详细信息

Lasted 2020-02-15 12:31:58

CPU 信息包含有关处理器的详细信息,例如体系结构,供应商名称,型号,内核数,每个内核的速度等信息。Linux 上有很多命令可以获取 CPU 硬件信息。

本篇文章,我们将查看如CPU架构,vendor_id,型号,型号名称,CPU内核数,每个内核的速度等信息。

本质上,/proc/cpuinfo 包含所有这些信息,其他每个命令都从该文件获取输出。

1. 使用cat命令获取CPU信息

您可以通过cat命令查看 /proc/cpuinfo 文件获取CPU的信息,如下所示:

cat /proc/cpuinfo
processor	: 0
vendor_id	: GenuineIntel
cpu family	: 6
model		: 60
model name	: Intel(R) Core(TM) i7-4790 CPU @ 3.60GHz
stepping	: 3
microcode	: 0x12
cpu MHz		: 3591.699
cache size	: 8192 KB
physical id	: 0
siblings	: 2
core id		: 0
cpu cores	: 2
apicid		: 0
initial apicid	: 0
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 mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts nopl xtopology tsc_reliable nonstop_tsc cpuid aperfmperf pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt aes xsave avx f16c rdrand hypervisor lahf_lm cpuid_fault pti fsgsbase smep xsaveopt dtherm ida arat pln pts
bugs		: cpu_meltdown spectre_v1 spectre_v2 spec_store_bypass l1tf mds swapgs
bogomips	: 7183.39
clflush size	: 64
cache_alignment	: 64
address sizes	: 40 bits physical, 48 bits virtual
power management:

processor	: 1
vendor_id	: GenuineIntel
cpu family	: 6
model		: 60
model name	: Intel(R) Core(TM) i7-4790 CPU @ 3.60GHz
stepping	: 3
microcode	: 0x12
cpu MHz		: 3591.699
cache size	: 8192 KB
physical id	: 0
siblings	: 2
core id		: 1
cpu cores	: 2
apicid		: 1
initial apicid	: 1
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 mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts nopl xtopology tsc_reliable nonstop_tsc cpuid aperfmperf pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt aes xsave avx f16c rdrand hypervisor lahf_lm cpuid_fault pti fsgsbase smep xsaveopt dtherm ida arat pln pts
bugs		: cpu_meltdown spectre_v1 spectre_v2 spec_store_bypass l1tf mds swapgs
bogomips	: 7183.39
clflush size	: 64
cache_alignment	: 64
address sizes	: 40 bits physical, 48 bits virtual
power management:

结合 grep 命令,可以过滤或统计输出结果,只显示供应商名称、型号、处理器数量和内核数量等信息,如下所示:

查看供应商
cat /proc/cpuinfo | grep 'vendor' | uniq
vendor_id	: GenuineIntel
查看型号
cat /proc/cpuinfo | grep 'model name' | uniq
model name	: Intel(R) Core(TM) i7-4790 CPU @ 3.60GHz
处理器数量
cat /proc/cpuinfo | grep processor | wc -l
2
单个内核
cat /proc/cpuinfo | grep 'core id'
core id		: 0
core id		: 1 

2. 使用lscpu命令显示CPU架构信息

lscpu命令根据 sysfs 和 /proc/cpuinfo 中显示CPU架构信息,如下所示:

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:  1
Core(s) per socket:  2
Socket(s):           1
NUMA node(s):        1
Vendor ID:           GenuineIntel
CPU family:          6
Model:               60
Model name:          Intel(R) Core(TM) i7-4790 CPU @ 3.60GHz
Stepping:            3
CPU MHz:             3591.699
BogoMIPS:            7183.39
Hypervisor vendor:   VMware
Virtualization type: full
L1d cache:           32K
L1i cache:           32K
L2 cache:            256K
L3 cache:            8192K
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 dts mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts nopl xtopology tsc_reliable nonstop_tsc cpuid aperfmperf pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt aes xsave avx f16c rdrand hypervisor lahf_lm cpuid_fault pti fsgsbase smep xsaveopt dtherm ida arat pln pts

3. 使用dmidecode命令显示Linux硬件信息

dmidecode 命令是用于查看Linux系统硬件信息的工具,通过 --type 参数指定查看处理器相关信息,如下所示:

dmidecode --type processor
# dmidecode 3.2
Getting SMBIOS data from sysfs.
SMBIOS 2.4 present.

Handle 0x0004, DMI type 4, 35 bytes
Processor Information
  Socket Designation: CPU socket #0
  Type: Central Processor
  Family: Unknown
  Manufacturer: GenuineIntel
  ID: C3 06 03 00 FF FB AB 1F
  Version: Intel(R) Core(TM) i7-4790 CPU @ 3.60GHz
  Voltage: 3.3 V
  External Clock: Unknown
  Max Speed: 30000 MHz
  Current Speed: 3600 MHz
  ......

4. 使用lshw工具显示CPU架构信息

lshw工具用于显示硬件配置的详细信息。可以使用 -C 参数来选择硬件类别,显示 CPU 信息如下所示:

lshw -C CPU
*-cpu:0                   
  description: CPU
  product: Intel(R) Core(TM) i7-4790 CPU @ 3.60GHz
  vendor: Intel Corp.
  physical id: 4
  bus info: cpu@0
  version: Intel(R) Core(TM) i7-4790 CPU @ 3.60GHz
  slot: CPU socket #0
  size: 3600MHz
  capacity: 4230MHz
  width: 64 bits
  ......

5. nproc命令显示处理器数量

nproc
2

除以上命令,还可安装 cpuidInxihardinfohwinfo 等命令查看CPU相关信息。