It is a no-brainer that the various Linux operating system distributions that provide irreplaceable performance prowess in a development or production environment will lose their performance identity in the absence of processors/cores.
These processors/cores are hardware entities of a computer system responsible for computing how fast the Linux operating system and its hosted programs complete user/system assigned tasks.
The evolution/innovation of various computer hardware infrastructures has led to the production of modern CPUs whose processors/cores embrace features like hyper-threading and multiple cores.
Importance of Knowing the Number of Processors/Cores in Linux
When working under an open-source operating system distribution like Linux, performance is everything. You need both the hardware and software components of your computing system to be at their best.
Therefore, knowing the number of processors/cores on the machine that powers your Linux operating system helps gauge how best your OS can perform under specific/customizable computing conditions.
For instance, you might be able to understand why multiple cores/hyper-threading CPUs have a speed and performance advantage over single-Core CPUs without hyper-threading.
1. Find Linux CPU Processors/Cores Using /proc/cpuinfo File
Whether on a remote Linux server or desktop Linux system, this method will query the /proc/cpuinfo file for lines matching the keyword processor via grep command which passes the processor keyword to a wc (word count) function that sums it up for display.
$ cat /proc/cpuinfo | grep processor | wc -l 4
A more detailed output of the above file will look like the following:
$ more /proc/cpuinfo
2. Get Linux CPU Processors/Cores Using lscpu Command
To understand what lscpu command does, we first need to run it:
$ lscpu
The lscpu command also highlights the CPU’s Architecture, op-mode(s), address sizes, thread(s) per core, core(s) per socket, family, model name, etc.
3. Check Linux CPU Processors/Cores Using top Command
Key in the command (top) on your Linux system and hit [Enter] on your keyboard. You should get a detailed output on what is going on with your processors/cores.
$ top
4. List Linux CPU Processors/Cores Using nproc Command
This approach is straightforward and will only output the available CPUs on your Linux system.
$ nproc --all 4
An alternative approach to execute this command is as follows:
$ echo "Threads/core: $(nproc --all)"
5. List Linux CPU Processors/Cores Using getconf Command
This command is straightforward and can be executed in the following manner:
$ getconf _NPROCESSORS_ONLN 4
An alternative approach to executing this command is as follows:
$ echo "Number of CPU/cores online at $HOSTNAME: $(getconf _NPROCESSORS_ONLN)"
6. Find Linux CPU Processors/Cores Using dmidecode Command
The dmidecodeis command is used to get the Linux system’s hardware related information such as Processor, RAM, BIOS detail, Memory, Serial numbers etc.
$ sudo dmidecode -t 4
We can alternatively modify the execution of the above command to provide us with CPU details like version, core count, core enabled, and thread count.
$ sudo dmidecode -t 4 | egrep -i 'core (count|enabled)|thread count|Version'
The above discussed inbuilt Linux commands cover everything there is to know about the number of processors/cores in your Linux system and much more.