...

How to determine number of CPUs on Linux using command line nixCraft

how-to-determine-number-of-cpus-on-linux-using-command-line-nixcraft

I am a new Linux system admin. How do I obtain the number of CPUs and cores in the Linux system from the command line? How do I determine the number of CPUs on Linux?

A CPU is an acronym for the central processing unit. It is an essential part of a computer. The CPU sends signals that control the other part of the Linux server. You can call it as the brain of your computer. This page show how to find out number of CPUs on Linux using command line.

Command to determine number of CPUs on Linux

The procedure is as follows:

  1. Log in into your Linux desktop
  2. Open the terminal application on Linux
  3. For remote server run ssh user@server-name
  4. To get CPU information type lscpu that display information about the CPU architecture of Linux including installed CPUs

Let us see all examples in details.

Linux determine number of CPUs using the lscpu command

Simply type the following command:
lscpu
Linux determine number of CPUs using lscpu command
From above output it is clear that:

  • Intel(R) Core(TM) i7-8650U CPU @ 1.90GHz – Model name (CPU name/make)
  • 1 – Socket(s) i.e. number of CPUs
  • 4 – Cores per socket
  • 2 – Thread(s) per core
  • 8 – 8 logical core (Hyper-threading) [cores per socket * threads per core]

How do I display the number of processing units available?

You can show the number of processing units available to the current process including all installed processors:
nproc --all
Sample outputs:

24

Another option to obtain the number of CPUs/cores in Linux

You can run the following command too:
getconf _NPROCESSORS_ONLN
Sample outputs:

8

Say hello to /proc/cpuinfo

Use the cat command to see info about your CPU and system architecture dependent items, for each supported architecture a different list:
cat /proc/cpuinfo
You can use the combination of grep command and wc command as follows to print

grep processor /proc/cpuinfo | wc -l echo "Total logical core(s): $(grep processor /proc/cpuinfo | wc -l)" echo "Core per cpu: $(grep '^core id' /proc/cpuinfo | sort -u | wc -l)"

Sample outputs:

Total logical core(s): 8
Core per cpu: 4

The output from /proc/cpuinfo can be difficult to phrase. Therefore, it is better to use the lscpu command:
lscpu
Sample outputs:

Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Byte Order: Little Endian
CPU(s): 24
On-line CPU(s) list: 0-23
Thread(s) per core: 1
Core(s) per socket: 1
Socket(s): 24
NUMA node(s): 1
Vendor ID: GenuineIntel
CPU family: 6
Model: 79
Model name: Intel(R) Xeon(R) CPU E5-2697 v4 @ 2.30GHz
Stepping: 1
CPU MHz: 2299.994
BogoMIPS: 4599.98
Hypervisor vendor: KVM
Virtualization type: full
L1d cache: 32K
L1i cache: 32K
L2 cache: 4096K
L3 cache: 16384K
NUMA node0 CPU(s): 0-23
Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon rep_good nopl xtopology cpuid tsc_known_freq 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 3dnowprefetch cpuid_fault invpcid_single pti fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm rdseed adx smap xsaveopt arat

Conclusion

Explains how to determine the number of CPUs, cores, and threads on Linux using lscpu and other commands. This information is useful for licensing third-party apps that work per socket or core.

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.

Discover more from WIREDGORILLA

Subscribe now to keep reading and get access to the full archive.

Continue reading