linux 系统查询CPU核心数

环境为1块双核心2GCPU

[root@mail ~]# cat /proc/cpuinfo 
processor   : 0
vendor_id   : GenuineIntel
cpu family  : 6
model       : 45
model name  : Intel(R) Xeon(R) CPU E5-2660 0 @ 2.20GHz
stepping    : 7
microcode   : 4294967295
cpu MHz     : 2199.976
cache size  : 20480 KB
physical id : 0                                       #物理计算,一块CPU
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 mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc rep_good xtopology unfair_spinlock pni pclmulqdq ssse3 cx16 pcid sse4_1 sse4_2 popcnt aes xsave avx hypervisor lahf_lm xsaveopt pti retpoline
bogomips    : 4399.95
clflush size    : 64
cache_alignment : 64
address sizes   : 44 bits physical, 48 bits virtual
power management:

processor   : 1
vendor_id   : GenuineIntel
cpu family  : 6
model       : 45
model name  : Intel(R) Xeon(R) CPU E5-2660 0 @ 2.20GHz
stepping    : 7
microcode   : 4294967295
cpu MHz     : 2199.976
cache size  : 20480 KB
physical id : 0                                   #物理计算,一块CPU
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 mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc rep_good xtopology unfair_spinlock pni pclmulqdq ssse3 cx16 pcid sse4_1 sse4_2 popcnt aes xsave avx hypervisor lahf_lm xsaveopt pti retpoline
bogomips    : 4399.95
clflush size    : 64
cache_alignment : 64
address sizes   : 44 bits physical, 48 bits virtual
power management:

[root@mail ~]# cat /proc/cpuinfo |grep "physical id"
physical id : 0
physical id : 0

如下直观计算

  • 物理CPU
[root@mail ~]# cat /proc/cpuinfo |grep "physical id"
physical id : 0
physical id : 0

计算机计数从0开始,故此,这里的查询结果为1,也就是一块物理CPU

  • 逻辑CPU
[root@mail ~]# cat /proc/cpuinfo |grep "core id"
core id     : 0
core id     : 1
[root@mail ~]# cat /proc/cpuinfo |grep "core id"|wc -l
2

统计获得共计2个核心

你可能感兴趣的:(linux)