获取CPU信息的shell脚本
2017-10-16 14:49
393 查看
#!/usr/bin/bash
#filename: cpu-info.sh
#this sctrpy only works in a Linux system which has one or more identical physical CPU(s).
#逻辑CPU个数
echo -n "logical CPU number in total: "
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."
ecit 0;
fi
#物理CPU个数
echo -n "physical CPU number in total: "
cat /proc/cpuinfo | grep "physical id" | sort | uniq | wc -l
#每个物理CPU上Core的个数(未计入超线程)
echo -n "core number in a physical CPU: "
core_per_phy_cpu=$(cat /proc/cpuinfo | grep "core id" | sort | uniq | wc -l)
echo $core_per_phy_cpu
#每个物理CPU中逻辑CPU(可能是core, threads 或both)的个数
echo -n "logical CPU number in a physical CPU: "
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”, 那么超线程是打开的
#此处根据前面计算的logical_cpu_per_phy_cpu和core_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's something wrong."
fi
#filename: cpu-info.sh
#this sctrpy only works in a Linux system which has one or more identical physical CPU(s).
#逻辑CPU个数
echo -n "logical CPU number in total: "
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."
ecit 0;
fi
#物理CPU个数
echo -n "physical CPU number in total: "
cat /proc/cpuinfo | grep "physical id" | sort | uniq | wc -l
#每个物理CPU上Core的个数(未计入超线程)
echo -n "core number in a physical CPU: "
core_per_phy_cpu=$(cat /proc/cpuinfo | grep "core id" | sort | uniq | wc -l)
echo $core_per_phy_cpu
#每个物理CPU中逻辑CPU(可能是core, threads 或both)的个数
echo -n "logical CPU number in a physical CPU: "
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”, 那么超线程是打开的
#此处根据前面计算的logical_cpu_per_phy_cpu和core_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's something wrong."
fi
相关文章推荐
- 获取服务器信息shell脚本:内存大小,cpu型号,系统发行版本,硬盘个数及大小等
- 获取服务器信息shell脚本:内存大小,cpu型号,系统发行版本,硬盘个数及大小等
- 获取服务器信息shell脚本:内存大小,cpu型号,系统发行版本,硬盘个数及大小等
- 通过shell脚本获取主机信息
- shell脚本获取系统相关信息
- shell脚本获取CPU利用率并记录到远程服务器的MYSQL数据库
- 获取系统信息#Shell脚本
- shell 脚本获取远程服务器信息并发送邮件
- 使用shell脚本采集系统cpu、内存、磁盘、网络等信息
- shell脚本之获取终端信息
- 脚本获取 app 的 cpu、memory 信息,使用 pychartdir 生成图表
- Java 连接远程Linux 服务器执行 shell 脚本查看 CPU、内存、硬盘信息
- 用shell脚本获取一个github项目所有文件的历史信息
- shell脚本之获取终端信息
- linux获取cpu利用率shell脚本
- 使用shell脚本采集系统cpu、内存、磁盘、网络等信息
- linux系统使用python获取cpu信息脚本分享
- linux系统使用python获取cpu信息脚本分享
- shell脚本获取输出到终端的所有信息
- Ubuntu下获取系统信息shell脚本