Use Shell scripts to obtain the CPU Topology

Source: Internet
Author: User
Article Title: use Shell scripts to obtain the CPU topology. Linux is a technology channel of the IT lab in China. Including desktop applications, Linux system management, kernel research, embedded systems, open source, and other basic categories. This is not a problem because everyone on Earth knows that cat/proc/cpuinfo gets CPU information. But can you see from that output that multiple physical CPUs, multi-core CPUs, or hyper-threading stuff?

This article provides a script and provides a clear answer through analysis of proc. The script I write may be less versatile. You can modify it based on the situation. Basically, there is no problem here.

Let's talk about the basics:
/Proc/cpuinfo:
Processor indicates the logical CPU number (core or thread)
Core id indicates the CPU core number.
Physical id indicates the physical CPU number

The script is as follows:
Cpu_p = 'cat/proc/cpuinfo | grep "physical id" | sort | uniq | wc-l'
Cpu_c = 'cat/proc/cpuinfo | grep "core id" | uniq | wc-l'
Cpu_l = 'cat/proc/cpuinfo | grep "processor" | wc-l'

C_p = 'expr $ cpu_c/$ cpu_p'
L_p = 'expr $ cpu_l/$ cpu_p'
T_c = 'expr $ cpu_l/$ cpu_c'

Echo "Physical CPU Count: $ cpu_p"
Echo "CPU Core Count: $ cpu_c"
Echo "Logical CPU Count: $ cpu_l"

Echo "$ c_p cores per physical CPU"
Echo "$ l_p logical CPUs per physical CPU"
Echo "$ t_c threads per core"

If [$ c_p-eq 1]; then
Echo "Your CPU is unicore"
Else
Echo "Your CPU is multicore"
Fi

If [$ t_c-eq 1]; then
Echo "Your CPU isn \'t of HT"
Else
Echo "Your CPU is of HT"
Fi

Echo "You have $ cpu_p CPUs, each CPU has $ c_p cores, each core has $ t_c threads. In summary $ cpu_c cores, $ cpu_l threads ."


The following is the running result here:
Related Article

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.