Display Number of Processors on Linux :-
On Linux, /proc/cpuinfo contains all of the processor information for all current processors in your computer. This will include the speed, the amount of on-chip cache, processor type, and how many cores.
Here’s the command:
cat /proc/cpuinfo | grep processor | wc -l
The command just looks in the /proc/cpuinfo file, pulls out the number of lines containing the word “processor” and passes them into wc (word count), which returns a count of the CPUs in the system.
Here’s what it returned on my remote server:
[root@root]# cat /proc/cpuinfo | grep processor | wc -l
4
Note that if you have a dual-core processor, it will return each core as a separate processor. You can look at the full output of cat /proc/cpuinfo to see if the chips are dual-core.
nproc ExampleThe nproc command shows the number of processing units available:
# nproc
Sample outputs:
8
lscpu Commandlscpu gathers CPU architecture information form /proc/cpuinfon in human-read-able format:
# lscpu
Sample outputs:
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Byte Order: Little Endian
CPU(s): 8
On-line CPU(s) list: 0-7
Thread(s) per core: 1
Core(s) per socket: 4
CPU socket(s): 2 NUMA node(s): 1
Vendor ID: GenuineIntel
CPU family: 6
Model: 15 Stepping: 7
CPU MHz: 1866.669
BogoMIPS: 3732.83
Virtualization: VT-x L1d
cache: 32K L1i
cache: 32K
L2 cache: 4096K
NUMA node0
CPU(s): 0-7