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: