本文给出一个脚本,通过分析proc来给出一个清晰的答案,本人写的脚本通用性可能比较差,大家根据情况进行修改,基本上在偶这里没啥问题。
先说点基础:
/proc/cpuinfo里面:
processor表示逻辑CPU号(核或线程)
core id表示CPU核号
physical id表示物理CPU号
脚本如下:
cpu_p=`cat /proc/cpuinfo | grep "physical id" | sort | uniq | wc -l` cpu_c=`cat /proc/cpuinfo | grep "core id" | uniq | wc -l` cpu_l=`cat /proc/cpuinfo | grep "processor" | wc -l` c_p=`expr $cpu_c / $cpu_p` l_p=`expr $cpu_l / $cpu_p` t_c=`expr $cpu_l / $cpu_c` echo "Physical CPU Count: $cpu_p" echo "CPU Core Count : $cpu_c" echo "Logical CPU Count: $cpu_l" echo "$c_p cores per physical CPU" echo "$l_p logical CPUs per physical CPU" echo "$t_c threads per core" if [ $c_p -eq 1 ]; then echo "Your CPU is unicore" else echo "Your CPU is multicore" fi if [ $t_c -eq 1 ]; then echo "Your CPU isn\'t of HT" else echo "Your CPU is of HT" fi echo "You have $cpu_p CPUs, each CPU has $c_p cores, each core has $t_c threads. In summary $cpu_c cores, $cpu_l threads." |
下面是在俺这里的运行结果:
时间:2009-07-29 20:39
来源:Linuxeden
作者:zltjiangshi
原文链接