linux怎么查询cpu核心数

linux怎么查询cpu核心数


慕田峪9158850
浏览 456回答 1
1回答

料青山看我应如是

1.查看逻辑CPU个数:#cat /proc/cpuinfo |grep "processor"|sort -u|wc -l242.由于有超线程技术有必要查看一下物理CPU个数:#grep "physical id" /proc/cpuinfo|sort -u|wc -l2#grep "physical id" /proc/cpuinfo|sort -uphysical id : 0physical id : 1查看每个物理CPU内核个数:#grep "cpu cores" /proc/cpuinfo|uniqcpu cores : 6每个物理CPU上逻辑CPU个数:#grep "siblings" /proc/cpuinfo|uniqsiblings : 12判断是否开启了抄超线程:如果多个逻辑CPU的"physical id"和"core id"均相同,说明开启了超线程或者换句话说逻辑CPU个数 > 物理CPU个数 * CPU内核数 开启了超线程逻辑CPU个数 = 物理CPU个数 * CPU内核数 没有开启超线程相关知识延伸阅读:一次性查询所有信息:#!/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 "*****************************"执行结果:#./cpuinfo****** CPU Information ******Logical CPU Number : 24Physical CPU Number : 2CPU Core Number : 6HT Number : 2
打开App,查看更多内容
随时随地看视频慕课网APP