How to find the number of CPU cores on Linux

Last updated on December 2, 2020 by Dan Nanni

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:
. . . .

Find the Number of Physical CPUs

The following command will show the number of physical CPU processors on board.

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

Find the Number of Cores per CPU

If you want to know how many cores each physical CPU processor has, use the following command.

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

Find the Total Number of Processors

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

$ 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. In this case, they are referred to as logical processors. Thus the total processor count seen by Linux is 16 (= 2 x 4 x 2).

Support Xmodulo

This website is made possible by minimal ads and your gracious donation via PayPal or credit card

Please note that this article is published by Xmodulo.com under a Creative Commons Attribution-ShareAlike 3.0 Unported License. If you would like to use the whole or any part of this article, you need to cite this web page at Xmodulo.com as the original source.

Xmodulo © 2021 ‒ AboutWrite for UsFeed ‒ Powered by DigitalOcean