如何获取Linux的CPU信息?

中央处理器是计算机的核心部件。CPU主要处理来自不同来源的数据。CPU为不同的处理需求提供了很多不同的特性。在Linux中,可以使用不同的命令列出这些特性和CPU信息。

null

/proc/cpuinfo文件

CPU信息最基本的来源之一是 /过程/处理信息 文件。大多数与CPU info相关的命令都从这个文件获取信息。作为简单文本文件 回声 命令可用于通过/proc/cpuinfo打印CPU信息。

cat /proc/cpuinfo

在提供以下信息的地方,输出非常详细。

processor    : 0vendor_id    : GenuineIntelcpu family    : 6model        : 158model name    : Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHzstepping    : 9microcode    : 0xb4cpu MHz        : 2808.005cache size    : 6144 KBphysical id    : 0siblings    : 1core id        : 0cpu cores    : 1apicid        : 0initial apicid    : 0fpu        : yesfpu_exception    : yescpuid level    : 22wp        : yesflags        : fpu vme de pse ... flush_l1d arch_capabilitiesvmx flags    : vnmi invvpid ept_x_only ... unrestricted_guest ple ept_mode_based_execbugs        : cpu_meltdown spectre_v1 spectre_v2 spec_store_bypass l1tf mds swapgs itlb_multihit srbdsbogomips    : 5616.01clflush size    : 64cache_alignment    : 64address sizes    : 45 bits physical, 48 bits virtualpower management:processor    : 1vendor_id    : GenuineIntelcpu family    : 6model        : 158model name    : Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHzstepping    : 9microcode    : 0xb4cpu MHz        : 2808.005cache size    : 6144 KBphysical id    : 2siblings    : 1core id        : 0cpu cores    : 1apicid        : 2initial apicid    : 2fpu        : yesfpu_exception    : yescpuid level    : 22wp        : yesflags        : fpu vme de pse tsc msr ... flush_l1d arch_capabilitiesvmx flags    : vnmi invvpid ept_x_only ... unrestricted_guest ple ept_mode_based_execbugs        : cpu_meltdown spectre_v1 spectre_v2 spec_store_bypass l1tf mds swapgs itlb_multihit srbdsbogomips    : 5616.01clflush size    : 64cache_alignment    : 64address sizes    : 45 bits physical, 48 bits virtualpower management:

lscpu命令

这个 lscpu command是另一个流行的命令,用于通过命令行界面列出CPU信息。cpuinfo命令以更可读的方式打印CPU信息。但是lscpu命令提供的信息比/proc/cpuinfo文件少。

lscpu

输出如下。

Architecture:                    x86_64CPU op-mode(s):                  32-bit, 64-bitByte Order:                      Little EndianAddress sizes:                   45 bits physical, 48 bits virtualCPU(s):                          2On-line CPU(s) list:             0,1Thread(s) per core:              1Core(s) per socket:              1Socket(s):                       2NUMA node(s):                    1Vendor ID:                       GenuineIntelCPU family:                      6Model:                           158Model name:                      Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHzStepping:                        9CPU MHz:                         2808.005BogoMIPS:                        5616.01Virtualization:                  VT-xHypervisor vendor:               VMwareVirtualization type:             fullL1d cache:                       64 KiBL1i cache:                       64 KiBL2 cache:                        512 KiBL3 cache:                        12 MiBNUMA node0 CPU(s):               0,1Vulnerability Itlb multihit:     KVM: Mitigation: VMX disabledVulnerability L1tf:              Mitigation; PTE Inversion; VMX flush not necessary, SMT disabledVulnerability Mds:               Mitigation; Clear CPU buffers; SMT Host state unknownVulnerability Meltdown:          Mitigation; PTIVulnerability Spec store bypass: Mitigation; Speculative Store ... and seccompVulnerability Spectre v1:        Mitigation; ...  and __user pointer sanitizationVulnerability Spectre v2:        Mitigation; Full generic retpoline, ... sabled, RSB fillingVulnerability Srbds:             Unknown: Dependent on hypervisor statusVulnerability Tsx async abort:   Not affectedFlags:                           fpu vme de pse tsc msr ... xsaves arat md_clear flush_l1 arch_capabilities
  • 建筑 列出CPU是32位还是64位或ARM处理器。
  • CPU操作模式 如果CPU运行32位或64位应用程序或两者都运行,则打印。
  • 型号名称 提供CPU的制造商和型号名称。

相关文章: 每分钟运行Cron作业

cpuid命令

这个 cpuid公司 命令提供类似的信息,其中CPU信息是使用CPUID指令提取的。它提供了供应商ID、CPU系列等信息。大多数Linux发行版都没有预装cpuid命令。cpuid可以如下安装。

为Ubuntu、Debian、Mint安装cpuid:

sudo apt install cpuid

为CentOS、RHEL、Fedora安装cpuid:

sudo yum install cpuid

安装之后,我们将运行cpuid命令,如下所示。cpuid命令分别列出处理器的每个核心。

cpuid

输出如下。

CPU 0:    vendor_id = "GenuineIntel"    version information (1/eax):       processor type  = primary processor (0)       family          = 0x6 (6)       model           = 0xe (14)       stepping id     = 0x9 (9)       extended family = 0x0 (0)       extended model  = 0x9 (9)       (family synth)  = 0x6 (6)       (model synth)   = 0x9e (158)       (simple synth)  = Intel Core (unknown type) (Kaby Lake / Coffee Lake) 14nm    miscellaneous (1/ebx):       process local APIC physical ID = 0x0 (0)       maximum IDs for CPUs in pkg    = 0x1 (1)       CLFLUSH line size              = 0x8 (8)       brand index                    = 0x0 (0)    brand id = 0x00 (0): unknown    feature information (1/edx):       x87 FPU on chip                        = true       VME: virtual-8086 mode enhancement     = true       DE: debugging extensions               = true       PSE: page size extensions              = true       TSC: time stamp counter                = true       RDMSR and WRMSR support                = true       PAE: physical address extensions       = true       MCE: machine check exception           = true...

dmidecode命令

dmi解码 是一个非常有用的命令,它可以简单地检索和显示所有硬件和相关信息。dmidecode不仅显示有关CPU的信息,还提供有关主板、RAM、显卡、HDD、SSD等的信息,以便仅显示与CPU相关的信息 –类型处理器 应提供参数。作为一个复杂的命令,dmidecode需要root权限才能访问详细信息。sudo命令可以提供根访问权限。

sudo dmidecode --type processor

输出如下。下面的信息是关于第一个CPU代码的,其编号为Core0,所有其他核心信息如下打印。

dmidecode 3.2 Getting SMBIOS data from sysfs. SMBIOS 2.7 present. Handle 0x0004, DMI type 4, 42 bytes Processor Information     Socket Designation: CPU #000     Type: Central Processor     Family: Unknown     Manufacturer: GenuineIntel     ID: E9 06 09 00 FF FB 8B 0F     Version: Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz     Voltage: 3.3 V     External Clock: Unknown     Max Speed: 30000 MHz     Current Speed: 2800 MHz     Status: Populated, Enabled     Upgrade: ZIF Socket     L1 Cache Handle: 0x0094     L2 Cache Handle: 0x0114     L3 Cache Handle: Not Provided     Serial Number: Not Specified     Asset Tag: Not Specified     Part Number: Not Specified     Core Count: 1     Core Enabled: 1     Characteristics:         64-bit capable         Execute Protection         Enhanced Virtualization...

inxi指挥部

这个 印西 是一个非常简单的工具,它提供了关于CPU的基本信息。对于流行的Linux发行版,inxi默认情况下不安装,可以按如下方式安装。

相关文章: Linux中如何计算行数?

Debian、Ubuntu、Mint、Kali:

sudo apt install inxi

CentOS、RHEL、Fedora:

sudo yum install inxi

inxi工具提供了关于所有硬件的信息,但是我们可以使用 -C级 选项以打印有关CPU或处理器的信息。

inxi -C

inxi输出的格式和颜色如下所示。

CPU:    Info: 2x Single Core model: Intel Core i7-7700HQ bits: 64 type: SMP L2 cache: 12.0 MiB            Speed: 2808 MHz min/max: N/A Core speeds (MHz): 1: 2808 2: 2808 

lshw命令

这个 lshw公司 是一个用来提取硬件详细信息的小工具。CPU或处理器信息可以通过使用-CPU选项列出,如下所示。lshw命令重新获得sudo命令可以提供的根权限。

sudo lshw -C CPU

输出如下。

*-cpu:0                           description: CPU        product: Intel(R) Core(TM) i7-10510U CPU @ 1.80GHz        vendor: Intel Corp.        physical id: 1        bus info: [email protected]        version: Intel(R) Core(TM) i7-10510U CPU @ 1.80GHz        slot: CPU #000        size: 2300MHz        capacity: 4230MHz        width: 64 bits        capabilities: lm fpu fpu_exce ... md_clear flush_l1d arch_capabilities        configuration: cores=4 enabledcores=4

硬信息工具(GUI)

这个 硬信息 工具是用于提供系统硬件信息的工具。hardinfo是一个图形化工具,它不同于我们列出的其他工具。hardinfo还为当前系统提供了基准。在大多数Linux发行版中,默认情况下不会安装hardinfo。

Debian、Mint、Kali、Ubuntu:

sudo apt install hardinfo

CentOS、RHEL、Fedora:

sudo yum install hardinfo

hardinfo工具可以从桌面环境的开始菜单打开,也可以从bashshell运行hardinfo命令。

hardinfo
图片[1]-如何获取Linux的CPU信息?-yiteyi-C++库
CPU信息的HardInfo工具

hwinfo命令

hwinfo命令提供有关Linux系统中当前硬件的详细信息。默认情况下不安装hwinfo,可以按如下方式安装。

相关文章: 如何在Ubuntu和Debian中添加Apt库?

Debian、Mint、Ubuntu、Kali:

sudo apt install hwinfo

RHEL、CentOS、Fedora:

sudo yum install hwinfo

get only CPU相关信息–CPU选项应提供如下所示。

hwinfo --cpu

输出如下。

01: None 00.0: 10103 CPU                                           [Created at cpu.465]   Unique ID: rdCR.j8NaKXDZtZ6   Hardware Class: cpu   Arch: X86-64   Vendor: "GenuineIntel"   Model: 6.142.12 "Intel(R) Core(TM) i7-10510U CPU @ 1.80GHz"   Features: fpu,vme,de,pse ... h_l1d,arch_capabilities   Clock: 2304 MHz   BogoMips: 4608.00   Cache: 8192 kb   Units/Processor: 4   Config Status: cfg=new, avail=yes, need=no, active=unknown
© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享