How to check number of CPUs are there in Linux system
One can use any one of the following command to find the number of physical CPU cores including all cores on Linux:
- lscpu command
- cat /proc/cpuinfo
- top or htop command
- nproc command
Just run the lscpu command:
$ lscpu
$ lscpu | egrep 'Model name|Socket|Thread|NUMA|CPU\(s\)'
$ lscpu -p
[root@shsdascn7i ~]# lscpu
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Byte Order: Little Endian
CPU(s): 2
On-line CPU(s) list: 0,1
Thread(s) per core: 1
Core(s) per socket: 1
Socket(s): 2
NUMA node(s): 1
Vendor ID: GenuineIntel
CPU family: 6
Model: 158
Model name: Intel(R) Core(TM) i7-8700 CPU @ 3.20GHz
Stepping: 10
CPU MHz: 3191.998
CPU max MHz: 0.0000
CPU min MHz: 0.0000
BogoMIPS: 6383.99
Hypervisor vendor: VMware
Virtualization type: full
L1d cache: 32K
L1i cache: 32K
L2 cache: 256K
L3 cache: 12288K
NUMA node0 CPU(s): 0,1
Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts mmx fxsr sse sse2 ss syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts nopl xtopology tsc_reliable nonstop_tsc aperfmperf 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 3dnowprefetch epb fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 invpcid rtm rdseed adx smap xsaveopt dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp
The following line indicates that I have two physical CPUs:
CPU socket(s): 2
cat /proc/cpuinfo
OR
$ more /proc/cpuinfo
[root@shsdascn7i ~]# cat /proc/cpuinfo
processor : 0
vendor_id : GenuineIntel
cpu family : 6
model : 158
model name : Intel(R) Core(TM) i7-8700 CPU @ 3.20GHz
stepping : 10
microcode : 0xb4
cpu MHz : 3191.998
cache size : 12288 KB
physical id : 0
siblings : 1
core id : 0
cpu cores : 1
apicid : 0
initial apicid : 0
fpu : yes
fpu_exception : yes
cpuid level : 22
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts mmx fxsr sse sse2 ss syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts nopl xtopology tsc_reliable nonstop_tsc aperfmperf 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 3dnowprefetch epb fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 invpcid rtm rdseed adx smap xsaveopt dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp
bogomips : 6383.99
clflush size : 64
cache_alignment : 64
address sizes : 42 bits physical, 48 bits virtual
power management:
processor : 1
vendor_id : GenuineIntel
cpu family : 6
model : 158
model name : Intel(R) Core(TM) i7-8700 CPU @ 3.20GHz
stepping : 10
microcode : 0xb4
cpu MHz : 3191.998
cache size : 12288 KB
physical id : 2
siblings : 1
core id : 0
cpu cores : 1
apicid : 2
initial apicid : 2
fpu : yes
fpu_exception : yes
cpuid level : 22
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts mmx fxsr sse sse2 ss syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts nopl xtopology tsc_reliable nonstop_tsc aperfmperf 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 3dnowprefetch epb fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 invpcid rtm rdseed adx smap xsaveopt dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp
bogomips : 6383.99
clflush size : 64
cache_alignment : 64
address sizes : 42 bits physical, 48 bits virtual
power management:
Let us print cpu thread count:
$ echo "CPU threads: $(grep -c processor /proc/cpuinfo)"
$ grep 'cpu cores' /proc/cpuinfo | uniq
top - 15:54:25 up 9 days, 23:17, 2 users, load average: 3.79, 2.87, 2.32
Tasks: 491 total, 1 running, 490 sleeping, 0 stopped, 0 zombie
%Cpu(s): 4.1 us, 6.0 sy, 0.0 ni, 29.1 id, 60.5 wa, 0.0 hi, 0.3 si, 0.0 st
KiB Mem : 9810952 total, 133368 free, 7078720 used, 2598864 buff/cache
KiB Swap: 12697596 total, 10402480 free, 2295116 used. 794624 avail Mem
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
12341 apdascn+ 20 0 1474108 81472 3028 S 16.9 0.8 0:39.14 java
28754 ordascn+ -2 0 2564436 2276 1876 S 1.3 0.0 293:00.05 ora_vktm_cdbebs
35 root 20 0 0 0 0 S 1.0 0.0 7:00.63 kswapd0
95348 apdascn+ 20 0 2841624 751960 0 S 0.7 7.7 4:30.52 java
9 root 20 0 0 0 0 S 0.3 0.0 6:04.69 rcu_sched
9661 root 20 0 0 0 0 S 0.3 0.0 1:41.58 jbd2/sdd1-8
9673 root 20 0 0 0 0 S 0.3 0.0 1:55.88 jbd2/sdc1-8
10467 root 20 0 0 0 0 S 0.3 0.0 0:00.56 kworker/0:0
12186 apdascn+ 20 0 1856860 290032 484 S 0.3 3.0 0:07.77 java
12524 root 20 0 162308 2660 1560 R 0.3 0.0 0:00.13 top
28770 ordascn+ 20 0 2672080 31740 27912 S 0.3 0.3 4:42.92 ora_scmn_cdbebs
28802 ordascn+ 20 0 2564440 35232 34200 S 0.3 0.4 5:37.36 ora_ckpt_cdbebs
97935 apdascn+ 20 0 1754184 136872 1632 S 0.3 1.4 0:35.74 java
99473 apdascn+ 20 0 2312444 865848 0 S 0.3 8.8 3:20.05 java
117218 ordascn+ 20 0 2568340 195068 189264 S 0.3 2.0 0:06.54 ora_m008_cdbebs
1 root 20 0 195224 3040 596 S 0.0 0.0 0:32.65 systemd
2 root 20 0 0 0 0 S 0.0 0.0 0:00.63 kthreadd
3 root 20 0 0 0 0 S 0.0 0.0 1:32.14 ksoftirqd/0
5 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kworker/0:0H
7 root rt 0 0 0 0 S 0.0 0.0 0:01.99 migration/0
8 root 20 0 0 0 0 S 0.0 0.0 0:00.00 rcu_bh
10 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 lru-add-drain
11 root rt 0 0 0 0 S 0.0 0.0 0:15.58 watchdog/0
Another option is to run lovely htop:
$ htop
Execute nproc print the number of CPUs available on Linux
Let us print the number of installed processors on your system i.e core count:
$ nproc --all
$ echo "Threads/core: $(nproc --all)"
Sample outputs:
[root@shsdascn7i ~]# echo "Threads/core: $(nproc --all)"
Threads/core: 2
Comments
Post a Comment