Home Linux Commands How to Get the Number of Processors/Cores in Linux

How to Get the Number of Processors/Cores in Linux

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 
Check Linux CPU Info
Check Linux CPU Info

2. Get Linux CPU Processors/Cores Using lscpu Command

To understand what lscpu command does, we first need to run it:

$ lscpu 
Check Linux CPU Architecture Information
Check Linux CPU Architecture Information

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
Monitor Linux CPU Usage
Monitor Linux CPU Usage

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)"
Find Linux CPU Cores
Find Linux CPU Cores

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)"
List Linux CPU Cores
List Linux CPU Cores

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
Check Linux Hardware Information
Check Linux Hardware Information

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'
Get Linux Hardware Information
Get Linux Hardware Information

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.

Ravi Saive
I am an Experienced GNU/Linux expert and a full-stack software developer with over a decade in the field of Linux and Open Source technologies. Founder of TecMint.com, LinuxShellTips.com, and Fossmint.com. Over 150+ million people visited my websites.

Each tutorial at UbuntuMint is created by a team of experienced writers so that it meets our high-quality standards.

Was this article helpful? Please add a comment to show your appreciation and support.

Got something to say? Join the discussion.

Thanks for choosing to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published or shared. Please Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.