To view the number of logical CPUs:
#cat /proc/cpuinfo |grep "processor"|sort -u|wc -l24
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 : 0physical id : 1
To view the number of cores per physical CPU:
#grep "cpu cores" /proc/cpuinfo|uniqcpu cores : 6
Number of logical CPUs on each physical CPU:
#grep "siblings" /proc/cpuinfo|uniqsiblings : 12
Determine if 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
逻辑CPU个数 > 物理CPU个数 * CPU内核数 开启了超线程逻辑CPU个数 = 物理CPU个数 * CPU内核数 没有开启超线程
Check all information at once:
#!/bin/bashphysicalNumber=0coreNumber=0logicalNumber=0HTNumber=0logicalNumber=$(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 $2}‘|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 : 24Physical CPU Number : 2CPU Core Number : 6HT Number : 2*****************************
How to view CPU count under Linux system