Identify Real CPU Cores in linux

Before I begin software installation I usually need to cross check the hardware specification of the provided hardware with requirements communicated to project owners. During this phase identification of CPU cores is mandatory to avoid performance issues in production environment.

Finding the number of CPU cores on a Linux server can be challenging. The way /proc/cpuinfo displays information makes it hard to distinguish between real CPU cores and logical hyperthreading CPU’s.
For example, consider if I run the following command on linux OS

$ cat /proc/cpuinfo | grep processor
processor : 0
processor : 1
processor : 2
processor : 3

The above output explains I have 4 CPU Cores however in reality there are only 2 CPU Cores , the other 2 Cores are virtual Cores which appears if hyper threading is enabled on your system

Using the following command we can tie all of this together to show the number of cores on a system:

$ cat /proc/cpuinfo | egrep "core id|physical id" | tr -d "\n" | sed s/physical/\\nphysical/g | grep -v ^$ | sort | uniq | wc -l

Linux |