How to find the number of CPU cores on Linux

Multi-core CPU processors are common nowadays, including dual-core processors (e.g., Intel Core Duo), quad-core processors (e.g., Intel Core i5), and hexa-core processors (e.g., AMD Phenom II X6). Also, many server-grade physical machines are equipped with more than one CPU processor. In order to find the number CPUs, and the number of cores per CPU, you can refer to /proc/cpuinfo.

A sample /proc/cpuinfo of HP Proliant DL 380 G7 server is as follows. The HP Proliant server is equipped with two Intel Xeon 5600 series processors.

processor       : 0
vendor_id       : GenuineIntel
cpu family      : 6
model           : 44
stepping        : 2
cpu MHz         : 2399.316
cache size      : 12288 KB
physical id     : 0
siblings        : 8
core id         : 0
cpu cores       : 4
apicid          : 0
initial apicid  : 0
fpu             : yes
fpu_exception   : yes
cpuid level     : 11
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 pni monitor ds_cpl vmx smx est tm2 ssse3 cx16 xtpr dca sse4_1 sse4_2 popcnt lahf_lm ida
bogomips        : 4802.28
clflush size    : 64
cache_alignment : 64
address sizes   : 40 bits physical, 48 bits virtual
power management:
. . . .

To find the number of physical CPUs:

$ cat /proc/cpuinfo | grep "^physical id" | sort | uniq | wc -l

To find the number of cores per CPU:

$ cat /proc/cpuinfo | grep "^cpu cores" | uniq
cpu cores       : 4

The total number of processors available is the number of physical CPUs multiplied by the number of cores per CPU.

To find the total number of processors:

$ cat /proc/cpuinfo | grep "^processor" | wc -l

Note that Intel Xeon 5600 series processors have Intel Hyper-Threading capability. So each core shows up as "two" processors in Linux, and thus the total processor count seen by Linux is 16 (= 2 x 4 x 2).

Subscribe to Xmodulo


The following two tabs change content below.

Leave a comment
