linux 测试cpu核脚本,查看cpu个数脚本

#!/bin/bash

#filename: cpuinfo.sh

#this scrip only works in linux system which has one or more indentical physcical CPU(s)

echo -n "logical CPU number in total: "

#逻辑cpu个数

cat /proc/cpuinfo |grep "processor" |wc -l

#有些系统没有多核也没有打开超线程,就直接退出脚本

cat /proc/cpuinfo |grep -qi "core id"

if [ $? -ne 0 ]; then

echo "warning. No multi-core or hyper-threading is enabled."

exit 0;

fi

echo -n "physical CPU number in total: "

#物理cpu个数

cat /proc/cpuinfo |grep "physical id" | sort | uniq |wc -l

echo -n "core number in a physical CPU: "

#每个物理CPU上Core的个数(未计入超线程)

core_per_phy_cpu=$(cat /proc/cpuinfo |grep "core id" | sort | uniq |wc -l)

echo $core_per_phy_cpu

echo -n "logic CPU number in a physical CPU: "

#每个物理CPU中逻辑CPU(可能是core,threads 或both)的个数

logic_cpu_per_phy_cpu=$(cat /proc/cpuinfo |grep "siblings" | sort | uniq |awk -F: '{print $2}')

echo $logic_cpu_per_phy_cpu

#是否打开有超线程

#如果在同一个物理CPU上有两个逻辑CPU具有相同的"core id" 那么超线程是打开的

#此处根据前面计算的core_per_phy_cpu和logic_core_per_phy_cpu的比较来查看超线程

if [ $logic_cpu_per_phy_cpu -gt $core_per_phy_cpu ]; then

echo"Hyper threading is enabled."

elif [ $logic_cpu_per_phy_cpu -eq $core_per_phy_cpu ]; then

echo "Hyper threading is NOT enabled."

else

echo "Error. There's something wrong."

fi

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值