查看服务器CPU信息工具脚本

从一本书上学到的,查看服务器CPU信息的工具


#!/bin/bash
#file: cpu-info.sh
#this script only works in a Linux system which has one or more identical physical 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 "logical CPU number in a physical CPU:"
#每个物理CPU中逻辑CPU(可能是core, threads或both)的个数
logical_cpu_per_phy_cpu=$(cat /proc/cpuinfo | grep "siblings" | sort | uniq | awk -F: '{print $2}')
echo $logical_cpu_per_phy_cpu

#是否打开有超线程
#如果在同一个物理CPU上两个逻辑CPU具有相同的"core id ",那么超线程是打开的
#此处根据前面的 core_per_phy_cpu 和 logical_cpu_per_phy_cpu 的比较来查看超线程 
if [ $logical_cpu_per_phy_cpu -gt $core_per_phy_cpu ]; then
        echo "Hyper threading is enabled"
elif [ $logical_cpu_per_phy_cpu -eq $core_per_phy_cpu ]; then
        echo "Hyper threading is NOT enabled"
else
        echo "Error, There is something wrong."
fi

运行结果:


另外还有一个查看CPU信息的地方

ls /sys/devices/system/cpu



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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值