X
    Categories: Linux

4 ways to find number of CPU-Cores in Linux


In my earlier post we had discuss about how to find top CPU consuming in Linux. Now we are going to discuss about how to find number of CPU-Cores in Linux.


Question: How to find number of CPU-Cores in Linux.

  • Using Proc filesystem

In order to find number of CPU-Cores in Linux we can take help of proc file system. This proc is an pseudo filesystem which keeps track of run-time environment. To Learn more about Proc file-system follow this link.

In order to get cpu information you need to simply cat “/proc/cpuinfo” file within proc. This gives in depth information about the CPU such as vendor_id, cpu family, model, cpu MHz etc. as below:

[root@ip-172-31-16-14 ~]# cat /proc/cpuinfo
processor       : 0
vendor_id       : GenuineIntel
cpu family      : 6
model           : 63
model name      : Intel(R) Xeon(R) CPU E5-2676 v3 @ 2.40GHz
stepping        : 2
microcode       : 0x25
cpu MHz         : 2394.660
cache size      : 30720 KB
physical id     : 0
siblings        : 4
core id         : 0
cpu cores       : 4
apicid          : 0
initial apicid  : 0
fpu             : yes
fpu_exception   : yes
cpuid level     : 13
wp              : yes
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx pdpe1gb rdtscp lm constant_tsc rep_good nopl xtopology eagerfpu pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm fsgsbase bmi1 avx2 smep bmi2 erms invpcid xsaveopt
bogomips        : 4789.01
clflush size    : 64
cache_alignment : 64
address sizes   : 46 bits physical, 48 bits virtual
power management:
-----OUTPUT TRUNCATED---------------------------

Hence to find number of CPU-Cores in Linux with exact details use below commands:

[root@ip-172-31-16-14 ~]# cat /proc/cpuinfo|grep processor
processor       : 0
processor       : 1
processor       : 2
processor       : 3
[root@ip-172-31-16-14 ~]# cat /proc/cpuinfo|grep processor|wc -l
4

Here in this case we have got 4 CPU’s ,numbers ranging from 0 to 3.

  • Using lscpu command

You can also find number of CPU-Cores in Linux using lscpu command.

[root@ip-172-31-16-14 ~]# lscpu
Architecture:          x86_64
CPU op-mode(s):        32-bit, 64-bit
Byte Order:            Little Endian
CPU(s):                4
On-line CPU(s) list:   0-3
Thread(s) per core:    1
Core(s) per socket:    4
Socket(s):             1
NUMA node(s):          1
Vendor ID:             GenuineIntel
CPU family:            6
Model:                 63
Model name:            Intel(R) Xeon(R) CPU E5-2676 v3 @ 2.40GHz
Stepping:              2
CPU MHz:               2394.660
BogoMIPS:              4789.01
Hypervisor vendor:     Xen
Virtualization type:   full
L1d cache:             32K
L1i cache:             32K
L2 cache:              256K
L3 cache:              30720K
NUMA node0 CPU(s):     0-3

In the above out put it’s clearly mentioned number of CPU’s as 4 against the “CPU(s)” heading.

  • Using nproc command

This nproc command helps you find number of CPU-Cores in Linux directly without any grep or calculation as below.

[root@ip-172-31-16-14 ~]# nproc
4
[root@ip-172-31-16-14 ~]#
  • Using dmidecode command

dmidecode command also gives information about CPU along with other hardware information such as System Information, Chassis Information. To get exact or find number of CPU-Cores in Linux with dmidecode command you need to grep it with the word CPU as below:

[root@ip-172-31-16-14 ~]# dmidecode |grep -i CPU
        Socket Designation: CPU 1
        Socket Designation: CPU 2
        Socket Designation: CPU 3
        Socket Designation: CPU 4
[root@ip-172-31-16-14 ~]#

 

View Comments (0)

Related Post