View Linux CPU Information

Source: Internet
Author: User

In the Linux system can be cat/proc/cpuinfo to view the relevant information on the CPU, through processor can determine the number of logical CPUs, physical ID can determine the number of physical CPUs, through the CPU Cores to determine the number of cores per CPU, siblings and CPU cores can be used to determine if hyper-threading is supported.

[Email protected] ~]$ cat/proc/cpuinfo |grep processor|wc-l

32

The above command can be used to determine the number of logical CPUs in this machine is 32

[Email protected] ~]$ cat/proc/cpuinfo |grep physical\ Id|sort|uniq

Physical id:0

Physical Id:1

The above output can be used to determine the number of physical CPUs in this machine is 2

[Email protected] ~]$ cat/proc/cpuinfo |grep cpu\ Cores|uniq

CPU Cores:8

The above output can be used to determine the number of cores for a single CPU is 8

[Email protected] ~]# cat/proc/cpuinfo |grep Sibling|uniq

Siblings:16


The result of the above output and the comparison with CPU cores can determine that the native supports Hyper-threading.

From the above results we can finally determine that there are 2 physical CPUs on this machine, 8 cores on each CPU, 2 threads on each core, and 32 logical CPUs from monitoring commands such as top or mpstat on the operating system.

Write the script as follows:

#!/bin/bash    # simple print cpu topology  # author:  hashlinux    function get_nr_processor ()   {       grep  ' ^processor '  /proc/cpuinfo | wc -l  }     function get_nr_socket ()   {      grep  ' physical  Id '  /proc/cpuinfo | awk -F:  ' {               print $2 |  "Sort -un"} '  | wc -l  }     function get_nr_siblings ()   {      grep   ' siblings '  /proc/cpuinfo | awk -F:  ' {               print $2 |  "Sort -un"} '   }     function&nBsp;get_nr_cores_of_socket ()   {      grep  ' Cpu cores '  / proc/cpuinfo | awk -f:  ' {               print $2 |  "Sort -un"} '   }    echo   ' ===== cpu topology table ===== '   echo    echo  ' + --------------+---------+-----------+ '   echo  ' | processor id | core id  | socket id | '   echo  ' +--------------+---------+-----------+ '     while read  line; do      if [ -z  "$line"  ]; then           printf  ' | %-12s | %-7s | %-9s  |\n '   $p _id  $c _id  $s _id          echo  ' +--------------+---------+-----------+ '            continue      fi        if  echo  "$line"  | grep -q  "^processor"; then           p_id= ' echo  ' $line  | awk -F:  ' {print $2} '  | tr  -d  '   '        fi         if echo  "$line"  | grep -q  "^core id"; then           c_id= ' echo  ' $line  | awk -F:  ' {print $ 2} '  | tr -d  '   '        fi         if echo  "$line"  | grep -q  "^physical id";  then            s_id= ' echo  "$line"  | awk -F:  ' {print $2} '  | tr -d  '   '        fi  done <  /proc/cpuinfo    echo    awk -F:  ' {        if  ($1 ~ /processor/)  {           gsub (/ /, "", $;          p_id=$2;)       } else if  ($1 ~ /physical id/) {           gsub (/ /, "", $;      )     s_id=$2;          arr[s_id]=arr[s_id ]  " "  p_id      }  }     end{       for  (I in arr)             printf  "socket %s:%s\n",  i, arr[i];  } '  /proc/cpuinfo     echo  echo  ' ===== cpu info summary ===== '   echo     nr_processor= ' get_nr_processor '   echo  "logical processors:  $nr _processor"     nr_socket= ' Get_nr_socket '   echo  "physical socket:  $nr _socket"     nr_siblings= ' get_nr_siblings '   echo  ' siblings in one  socket:  $nr _siblings "    nr_cores= ' Get_nr_cores_of_socket '   echo " cores in one socket:  $nr _cores "    let nr_cores*=nr_socket   echo  "cores in total:  $nr _cores"     if [  "$nr _cores"  =  "$nr _processor"  ];  then      echo  "Hyper-threading: off"   else       echo  "Hyper-threading: on"   fi    echo   echo  ' ===== end ===== '



Resources:

http://www.qingran.net/2011/09/numa%E5%BE%AE%E6%9E%B6%E6%9E%84/

Http://www.searchtb.com/2012/12/%E7%8E%A9%E8%BD%ACcpu-topology.html

Http://kodango.com/cpu-topology


This article is from the "lake and Laughter" blog, please make sure to keep this source http://hashlinux.blog.51cto.com/9647696/1792411

View Linux CPU Information

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.