• cpu 核数及逻辑数统计


    查看逻辑CPU个数:
    cat /proc/cpuinfo |grep "processor"|sort -u|wc -l
    24

    查看物理CPU个数:
    grep "physical id" /proc/cpuinfo|sort -u|wc -l                  
    2

    grep "physical id" /proc/cpuinfo|sort -u                  
    physical id     : 0
    physical id     : 1

    查看每个物理CPU内核个数:
    grep "cpu cores" /proc/cpuinfo|uniq
    cpu cores       : 6

    每个物理CPU上逻辑CPU个数:
    grep "siblings" /proc/cpuinfo|uniq
    siblings        : 12

    判断是否开启了抄超线程:
    如果多个逻辑CPU的"physical id"和"core id"均相同,说明开启了超线程

    或者换句话说
    逻辑CPU个数 > 物理CPU个数 * CPU内核数   开启了超线程

    逻辑CPU个数 = 物理CPU个数 * CPU内核数   没有开启超线程

     

    一次性查询所有信息:
    #!/bin/bash
     
    physicalNumber=0
    coreNumber=0
    logicalNumber=0
    HTNumber=0
     
    logicalNumber=$(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  : 24
    Physical CPU Number : 2
    CPU Core Number     : 6
    HT Number           : 2
    *****************************

     

  • 相关阅读:
    客户端技术的一点思考(数据存储用SQLite, XMPP通讯用Gloox, Web交互用LibCurl, 数据打包用Protocol Buffer, socket通讯用boost asio)
    自绘LISTVIEW的滚动条(Delphi实现)
    文字滚屏控件(SliderPanel)
    自动注册服务NET Core扩展IServiceCollection
    Three.js基础
    Cordova+Asp.net Mvc+GIS
    Netty
    TagHelper
    jQuery、实例大全
    React和Angular
  • 原文地址:https://www.cnblogs.com/tangshengwei/p/4680663.html
Copyright © 2020-2023  润新知