发布网友 发布时间:2022-04-19 22:06
共1个回答
热心网友 时间:2022-05-20 14:05
1、查看逻辑CPU个数:#cat /proc/cpuinfo grep "processor"sort -uwc -l2、查看物理CPU个数:#grep "physical id" /proc/cpuinfosort -uwc -l #grep "physical id" /proc/cpuinfosort -u physical id : 0physical id : 1 3、查看每个物理CPU内核个数:#grep "cpu cores" /proc/cpuinfouniqcpu cores : 6 4、每个物理CPU上逻辑CPU个数:#grep "siblings" /proc/cpuinfouniqsiblings : 12 5、判断是否开启了抄超线程:如果多个逻辑CPU的"physical id"和"core id"均相同,说明开启了超线程或者换句话说 逻辑CPU个数 > 物理CPU个数 * CPU内核数 开启了超线程 逻辑CPU个数 = 物理CPU个数 * CPU内核数 没有开启超线程 6、一次性查询所有信息: #!/bin/bash physicalNumber=0coreNumber=0logicalNumber=0HTNumber=0 logicalNumber=$(grep "processor" /proc/cpuinfosort -uwc -l)physicalNumber=$(grep "physical id" /proc/cpuinfosort -uwc -l)coreNumber=$(grep "cpu cores" /proc/cpuinfouniqawk -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 "*****************************"执行结果:#./cpuinfo ****** CPU Information ******Logical CPU Number : 24Physical CPU Number : 2CPU Core Number : 6HT Number : 2*****************************