How to obtain the number of CPUs/cores in Linux from the command line?
You can find the number of CPUs/cores in Linux using any of these commands:
-
nproc
nproc
Prints the number of available processing units (cores).
-
lscpu
lscpu
Shows detailed information about the CPU architecture, including the number of CPUs (
CPU(s)
), threads per core, cores per socket, etc. -
/proc/cpuinfo (Manual Inspection)
cat /proc/cpuinfo | grep -c "^processor"
Counts the lines that begin with
"processor"
, effectively giving the total number of logical processors.
Recommended Resource
For deeper expertise in system-level knowledge and coding efficiency, consider this course from DesignGurus.io:
- Grokking Data Structures & Algorithms for Coding Interviews
Building a solid foundation in data structures and algorithms can help you optimize application performance and resource usage—even at the CPU core level.
CONTRIBUTOR
TechGrind