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
model name      : Intel(R) Xeon(R) CPU           E5620  @ 2.40GHz
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
2

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
16

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

Do you want to receive Linux FAQs, detailed tutorials and tips published at Xmodulo? Enter your email address below, and we will deliver our Linux posts straight to your email box, for free. Delivery powered by Google Feedburner.

The following two tabs change content below.
Dan Nanni is the founder and also a regular contributor of Xmodulo.com. He is a Linux/FOSS enthusiast who loves to get his hands dirty with his Linux box. He likes to procrastinate when he is supposed to be busy and productive. When he is otherwise free, he likes to watch movies and shop for the coolest gadgets.

Leave a comment

Your email address will not be published. Required fields are marked *

Current ye@r *