linux 如何查cpu
- Linux
- 2025-08-07
- 4
lscpu
命令查看 CPU 信息,或使用
cat /proc/cpuinfo
查看详细
CPU 信息。
Linux 系统中,有多种方法可以查看 CPU 的相关信息,以下为您详细介绍:
使用 lscpu
命令
lscpu
命令是专门用于显示 CPU 架构信息的工具,它会提供关于 CPU 型号、核心数量、线程数、CPU 频率等详细信息。
运行 lscpu
命令后,输出示例如下:
| 属性 | 值 |
|———————|——————————————————————–|
| Architecture | x86_64 |
| CPU op-mode(s) | 32-bit, 64-bit |
| Byte Order | Little Endian |
| CPU(s) | 8 |
| On-line CPU(s) list | 0-7 |
| Thread(s) per core | 2 |
| Core(s) per socket | 4 |
| Socket(s) | 1 |
| Vendor ID | GenuineIntel |
| CPU family | 6 |
| Model | 158 |
| Model name | Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz |
| Stepping | 10 |
| CPUs shifted | 0 |
| CPU(s) max | 8 |
| CPU(s) min | 8 |
| BogoMIPS | 36000.00 |
| Virtualization | VT-x |
| L1d cache | 128 KiB |
| L1i cache | 128 KiB |
| L2 cache | 1 MiB |
| L3 cache | 8 MiB |
| NUMA node(s) | 1 |
| Vulnerability Itibs | Not affected |
| Vulnerability Mds | Not affected |
| Vulnerability Spe | Not affected |
| Vulnerability Cve-2017-5715 | Not affected |
| Flags | fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cap pln pts dts acpi mmu … |
从上述输出中,我们可以清晰地了解到该 CPU 是英特尔酷睿 i7 8550U,具有 4 个核心,每个核心支持 2 个线程,总共有 8 个逻辑处理器,CPU 频率为 1.80GHz,以及缓存大小、虚拟化支持等详细信息。
查看 /proc/cpuinfo
文件
/proc/cpuinfo
是一个虚拟文件,包含了系统 CPU 的详细信息,可以使用 cat
、less
或 more
等命令来查看其内容。
运行 cat /proc/cpuinfo
,部分输出如下:
processor : 0
vendor_id : GenuineIntel
cpu family : 6
model : 158
model name : Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz
stepping : 10
cpu MHz : 1800.000
cache size : 9216 KB
physical id : 0
siblings : 8
core id : 0
cpu cores : 4
apicid : 0
initial apicid : 0
fpu : yes
fpu_exception : yes
cpuid level : 22
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cap pln pts dts acpi mmu ...
bugs :
bogomips : 36000.00
...
通过查看这个文件,我们可以获得每个 CPU 核心的详细信息,包括处理器编号、厂商 ID、CPU 系列、型号、名称、频率、缓存大小、物理 ID、核心 ID、APIC ID、支持的指令集标志等,这些信息对于深入了解 CPU 的硬件特性和性能非常有帮助,如果您想了解 CPU 是否支持某些特定的指令集,可以在这个文件中查找 flags
字段。
使用 top
和 htop
命令(需安装 htop
)
top
命令是一个实时的系统任务管理器,它可以显示系统中各个进程的资源使用情况,包括 CPU 使用率,在 top
命令的输出中,可以看到每个 CPU 核心的使用百分比,以及整体的 CPU 使用情况。
运行 top
命令后,输出示例如下:
top 18:45:23 up 1 day, 3:22, 3 users, load average: 0.12, 0.08, 0.05
Tasks: 145 total, 1 running, 144 sleeping, 0 stopped, 0 zombie
%Cpu(s): 3.2 us, 1.5 sy, 0.0 ni, 95.2 id, 0.0 wa, 0.0 hi, 0.1 si, 0.0 st
KiB Mem : 7989856 total, 567896 free, 456789 used, 7021024 buff/cache
KiB Swap: 2097148 total, 2097148 free, 0 used. 6543212 avail Mem
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
1 root 20 0 45678 3456 1236 S 0.2 0.0 0:01.23 systemd
10 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kworker/u8:0
...
%Cpu(s)
行显示了 CPU 的使用情况,us
表示用户空间占用 CPU 的百分比,sy
表示内核空间占用 CPU 的百分比,ni
表示改变过优先级的用户进程占用 CPU 的百分比,id
表示空闲 CPU 的百分比,wa
表示等待 I/O 的 CPU 时间百分比,hi
表示硬中断处理占用 CPU 的百分比,si
表示软中断处理占用 CPU 的百分比,st
表示被其他虚拟机偷走的 CPU 时间百分比。
htop
命令是 top
命令的一个增强版,它提供了一个更直观、更易于使用的界面,在 htop
中,可以通过上下箭头键选择不同的进程,查看每个进程的详细 CPU 使用情况,还可以通过左右箭头键切换查看不同 CPU 核心的使用情况。htop
还支持彩色显示,使得信息更加清晰易读。
使用 dmidecode
命令(需超级用户权限)
dmidecode
命令可用于获取系统硬件的详细信息,包括 CPU、内存、主板等,要查看 CPU 信息,可以使用 sudo dmidecode -t processor
命令。
运行 sudo dmidecode -t processor
后,输出示例如下:
# dmidecode 3.2
SMBIOS 3.0 present.
Handle 0x0008, DMI type 4, 42 bytes
Processor Information
Socket Designation: CPU Socket
Type: Central Processor
Family: Core i7
Model: Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz
Stepping: A1
OEM Version: Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz
Current Speed: 1800 MHz
Max Speed: 4000 MHz
Voltage: 0.8 V
External Clock: 100 MHz
Max Case Temperature: 100 °C
Configuration: Thermal Management, Power Management, Hardware Prefetch, ...
Status: Populated, Enabled
Upgrade: Other
L1 Cache Handling: Unified L1 Data/Instruction Cache, Simultaneously Decoded and Retired, ...
L2 Cache Handling: Unified L2 Cache, Simultaneously Decoded and Retired, ...
L3 Cache Handling: Unified L3 Cache, Simultaneously Decoded and Retired, ...
Serial Number: To Be Filled By O.E.M.
Asset Tag: Not Available
Part Number: Not Available
dmidecode
命令提供的 CPU 信息更加详细和全面,包括 CPU 的制造商、型号、序列号、电压、温度、缓存信息、配置信息等,这些信息对于硬件管理和故障排除非常有用,如果您怀疑 CPU 的温度过高,可以通过查看 Max Case Temperature
字段来了解 CPU 的最大允许温度。
介绍了在 Linux 系统中查看 CPU 信息的几种常用方法。lscpu
命令简单直接,提供了 CPU 的基本信息;/proc/cpuinfo
文件包含了详细的 CPU 硬件信息;top
和 htop
命令可以实时查看 CPU 的使用情况;dmidecode
命令则提供了更全面的硬件信息,但需要超级用户权限,根据具体的需求,可以选择合适的方法来查看 CPU 信息。
FAQs
问题 1:如何查看 CPU 的核心数量?
答:可以使用 lscpu
命令,在输出结果中找到 Core(s) per socket
字段,其值即为 CPU 的核心数量,查看 /proc/cpuinfo
文件,统计 processor
字段出现的次数,也可以得到 CPU 的核心数量(注意区分物理核心和逻辑核心),还可以使用 nproc
命令,它会返回当前系统可用的处理器数量,对于多核 CPU,这个数量通常等于核心数量乘以线程数。
问题 2:如何确定 CPU 是否支持超线程技术?
答:使用 lscpu
命令,查看 Thread(s) per core
字段,如果该值大于 1,则表示 CPU 支持超线程技术,在 /proc/cpuinfo
文件中,查找 siblings
和 cpu cores
字段,siblings
的值大于 cpu cores
的值,也说明 CPU 支持超线程,一些 CPU 信息查看工具如 cpu-z
(在 Linux 下可通过 wine 等工具运行)也可以直观地显示 CPU 是否支持