如何查找包括虚拟在内的 CPU 核心数?

如何查找包括虚拟在内的 CPU 核心数?

如何使用命令行找出我的 CPU 的核心数量,包括虚拟核心(超线程核心)?

答案1

你可以计算一下 CPU 的数量

cat /proc/cpuinfo | grep processor | wc -l

输出 :

2

检查核心数量!

cat /proc/cpuinfo | grep 'core id'
core id         : 0
core id         : 1

或者

 $ nproc
 2

或者 lscpu 将显示所有输出:

lscpu

Architecture:          i686
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
Vendor ID:             GenuineIntel
CPU family:            15
Model:                 4
Stepping:              7
CPU MHz:               2792.992
BogoMIPS:              5585.98
L1d cache:             16K
L2 cache:              1024K

答案2

为了补充现有答案,您可以通过查看 /proc/cpuinfo 中的“兄弟”行来确定有关英特尔超线程的信息。下面的示例来自一台 2 插槽机器。它显示 CPU 有 6 个内核,但有 12 个“兄弟”。在英特尔 CPU 上,这意味着启用了超线程,并且有 6 个物理内核。

processor       : 23
vendor_id       : GenuineIntel
cpu family      : 6
model           : 62
model name      : Intel(R) Xeon(R) CPU E5-2430 v2 @ 2.50GHz
stepping        : 4
microcode       : 0x428
cpu MHz         : 1599.707
cache size      : 15360 KB
physical id     : 1
siblings        : 12
core id         : 5
cpu cores       : 6
apicid          : 43
initial apicid  : 43
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 acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf eagerfpu pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm ida arat xsaveopt pln pts dtherm tpr_shadow vnmi flexpriority ept vpid fsgsbase smep erms
bogomips        : 5005.20
clflush size    : 64
cache_alignment : 64
address sizes   : 46 bits physical, 48 bits virtual
power management:

dmidecode 对于确定 Linux 系统正在运行的硬件也很有用。

答案3

/proc/cpuinfo包含我的计算机的所有 CPU,包括虚拟 CPU。你可以用一点点来计算它们grep

grep -Pc '^processor\t' /proc/cpuinfo

答案4

您还可以安装htop(的更高级版本top),它将显示您的所有核心。

sudo apt-get install htop

然后启动它:htop

相关内容