To view the number of logical CPUs:
Cat/proc/cpuinfo |grep "Processor" |sort-u|wc-l
24
To view the number of physical CPUs:
grep "Physical ID"/proc/cpuinfo|sort-u|wc-l
2
grep "Physical ID"/proc/cpuinfo|sort-u
Physical id:0
Physical Id:1
To view the number of cores per physical CPU:
grep "CPU Cores"/proc/cpuinfo|uniq
CPU Cores:6
Number of logical CPUs on each physical CPU:
grep "siblings"/proc/cpuinfo|uniq
Siblings:12
To determine if a copy of Hyper-threading is turned on:
If the "Physical ID" and "core ID" of multiple logical CPUs are the same, the description turns on Hyper-threading
or in other words
Number of logical CPUs > number of physical CPUs * CPU cores turned on Hyper-threading
Number of logical CPUs = number of physical CPUs * CPU cores No Hyper-threading is turned on
Check all information at once:
#!/bin/bash
Physicalnumber=0
Corenumber=0
Logicalnumber=0
Htnumber=0
logicalnumber=$ (grep "Processor"/proc/cpuinfo|sort-u|wc-l)
physicalnumber=$ (grep "Physical ID"/proc/cpuinfo|sort-u|wc-l)
corenumber=$ (grep "CPU Cores"/proc/cpuinfo|uniq|awk-f ': ' {print $} ' |xargs)
htnumber=$ ((Logicalnumber/(Physicalnumber * corenumber))
echo "****** CPU information ******"
echo "Logical CPU number: ${logicalnumber}"
echo "Physical CPU number: ${physicalnumber}"
echo "CPU Core number: ${corenumber}"
echo "HT number: ${htnumber}"
echo "*****************************"
Execution Result:
./cpuinfo
CPU information ******
Logical CPU number:24
Physical CPU Number:2
CPU Core Number:6
HT Number:2
*****************************
CPU cores and logical count statistics