在Linux系统中,查看CPU信息有多种方法,以下是一些常用的命令:
lscpu
命令lscpu
命令提供了关于CPU架构的详细信息。
lscpu
输出示例:
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Byte Order: Little Endian
CPU(s): 4
On-line CPU(s) list: 0-3
Thread(s) per core: 2
Core(s) per socket: 2
Socket(s): 1
NUMA node(s): 1
Vendor ID: GenuineIntel
CPU family: 6
Model: 142
Model name: Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz
Stepping: 9
CPU MHz: 2712.000
BogoMIPS: 5424.00
Virtualization: VT-x
L1d cache: 32K
L1i cache: 32K
L2 cache: 256K
L3 cache: 3072K
NUMA node0 CPU(s): 0-3
/proc/cpuinfo
文件通过读取 /proc/cpuinfo
文件可以获得详细的CPU信息。
cat /proc/cpuinfo
输出示例:
processor : 0
vendor_id : GenuineIntel
cpu family : 6
model : 142
model name : Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz
stepping : 9
microcode : 0xea
cpu MHz : 2712.000
cache size : 3072 KB
physical id : 0
siblings : 4
core id : 0
cpu cores : 2
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 cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf tsc_known_freq pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb invpcid_single pti ssbd ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid mpx rdseed adx smap clflushopt intel_pt xsaveopt xsavec xgetbv1 xsaves dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp md_clear flush_l1d
bugs : cpu_meltdown spectre_v1 spectre_v2 spec_store_bypass l1tf mds swapgs itlb_multihit srbds
bogomips : 5424.00
clflush size : 64
cache_alignment : 64
address sizes : 39 bits physical, 48 bits virtual
power management:
top
命令top
命令可以实时显示系统中各个进程的资源占用情况,包括CPU使用率。
top
输出示例:
top - 14:30:00 up 1 day, 3:45, 2 users, load average: 0.00, 0.01, 0.05
Tasks: 169 total, 1 running, 168 sleeping, 0 stopped, 0 zombie
%Cpu(s): 0.3 us, 0.0 sy, 0.0 ni, 99.7 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
KiB Mem : 8078768 total, 2345676 free, 2456789 used, 3276303 buff/cache
KiB Swap: 2097148 total, 2097148 free, 0 used. 5345678 avail Mem
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
1234 user 20 0 23456 2345 2345 S 0.3 0.0 0:00.01 command_name
htop
命令htop
是 top
的一个增强版本,提供了更直观的界面和更多的功能。
sudo apt-get install htop # 安装htop(如果未安装)
htop
mpstat
命令mpstat
可以显示每个CPU的使用情况。
sudo apt-get install sysstat # 安装sysstat(如果未安装)
mpstat -P ALL
输出示例:
Linux 5.4.0-77-generic (hostname) 06/10/2021 _x86_64_
09:30:01 AM CPU %usr %nice %sys %iowait %irq %soft %steal %guest %gnice %idle
09:30:01 AM all 0.38 0.00 0.19 0.00 0.00 0.00 0.00 0.00 0.00 99.43
09:30:01 AM 0 0.78 0.00 0.39 0.00 0.00 0.00 0.00 0.00 0.00 98.83
09:30:01 AM 1 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00
htop
或 mpstat
需要先安装。htop
或 mpstat
需要先安装。grep
或其他文本处理工具过滤关键信息。grep
或其他文本处理工具过滤关键信息。通过这些方法,你可以全面了解Linux系统中CPU的详细信息和运行状态。
领取专属 10元无门槛券
手把手带您无忧上云