在Linux上如何查看服务器有几个CPU

时间:2019-11-20 08:53:49  来源:igfitidea点击:

Linux上如何查看CPU的数量?
如何使用命令获取Linux系统中的CPU和内核数?
如何确定Linux上的CPU数量?

Linux使用lscpu命令确定CPU数量

只需执行以下命令:

lscpu

输出示例:

Architecture:          x86_64
CPU op-mode(s):        32-bit, 64-bit
Byte Order:            Little Endian
CPU(s):                24
On-line CPU(s) list:   0-23
Thread(s) per core:    1
Core(s) per socket:    1
Socket(s):             24
NUMA node(s):          1
Vendor ID:             GenuineIntel
CPU family:            6
Model:                 79
Model name:            Intel(R) Xeon(R) CPU E5-2697 v4 @ 2.30GHz
Stepping:              1
CPU MHz:               2299.994
BogoMIPS:              4599.98
Hypervisor vendor:     KVM
Virtualization type:   full
L1d cache:             32K
L1i cache:             32K
L2 cache:              4096K
L3 cache:              16384K
NUMA node0 CPU(s):     0-23
Flags:                 fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon rep_good nopl xtopology cpuid tsc_known_freq pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch cpuid_fault invpcid_single pti fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm rdseed adx smap xsaveopt arat

查看可用的CPU数量?

查看当前进程可用的CPU数,包括所有已安装的CPU:

nproc --all

输出示例:

24

查看服务器CPU数量的另一种方法

执行以下命令:

getconf _NPROCESSORS_ONLN

输出示例:

8

/proc/cpuinfo文件

/proc/cpuinfo文件包含了有关CPU和系统体系结构的相关信息:

cat /proc/cpuinfo

使用grep和wc命令可以统计出CPU的数量:

grep processor /proc/cpuinfo | wc -l
echo "Total logical core(s): $(grep processor /proc/cpuinfo | wc -l)"
echo "Core per cpu: $(grep '^core id' /proc/cpuinfo | sort -u | wc -l)"

输出示例:

Total logical core(s): 8
Core per cpu: 4