CentOS 7.4查看CPU信息(含脚本)

Physical id 	#相同表示为同一个物理CPU
Processor 	#逻辑CPU
Cpu cores 	#CPU核数,内核个数
Core id 	#内核id号
Siblings 	#每个物理CPU里面的逻辑CPU个数
  • 查看CPU型号
[root@testhost ~]# cat /proc/cpuinfo | grep name | cut -f2 -d: | uniq -c
      4  Intel(R) Core(TM) i7 CPU       M 620  @ 2.67GHz
[root@testhost ~]# 
  • 查看物理CPU个数
[root@testhost ~]# cat /proc/cpuinfo | grep "physical id" | sort -u | wc -l  
2
  • 查看逻辑CPU个数
[root@testhost ~]# cat /proc/cpuinfo | grep "processor" | wc -l  
4
  • 查看CPU内核数
[root@testhost ~]# cat /proc/cpuinfo | grep "cpu cores" | uniq  
cpu cores       : 2
  • 查看单个物理CPU封装的逻辑CPU数量
[root@testhost ~]# cat /proc/cpuinfo | grep "siblings" | uniq  
siblings        : 2
  • 计算是否开启超线程

逻辑CPU > 物理CPU x CPU核数 #开启超线程
逻辑CPU = 物理CPU x CPU核数 #没有开启超线程或不支持超线程

  • 查看是否超线程
[root@testhost ~]# cat /proc/cpuinfo | grep -e "cpu cores"  -e "siblings" | sort | uniq
cpu cores       : 2
siblings        : 2

说明:如果cpu cores数量和siblings数量一致,则没有启用超线程,否则超线程被启用。

  • 脚本
[root@testhost ~]# cat cpu.sh   
#!/bin/bash
cpuname=$(cat /proc/cpuinfo | grep name | cut -f2 -d: | uniq -c)
physical=$(cat /proc/cpuinfo | grep "physical id" | sort -u | wc -l)
processor=$(cat /proc/cpuinfo | grep "processor" | wc -l)
cpucores=$(cat /proc/cpuinfo  | grep "cpu cores" | uniq)
siblings=$(cat /proc/cpuinfo  | grep "siblings"  | uniq)

echo "* * * * * CPU Information * * * * *"
echo "(CPU型号)cpu name : $cpuname"
echo "(物理CPU个数)physical id is : $physical"
echo "(逻辑CPU个数)processor is : $processor"
echo "(CPU内核数)cpu cores is : $cpucores"
echo "(单个物理CPU的逻辑CPU数)siblings is : $siblings"
[root@testhost ~]# 
  • 脚本运行效果
[root@testhost ~]# sh cpu.sh 
* * * * * CPU Information * * * * *
(CPU型号)cpu name :       4  Intel(R) Core(TM) i7 CPU       M 620  @ 2.67GHz
(物理CPU个数)physical id is : 2
(逻辑CPU个数)processor is : 4
(CPU内核数)cpu cores is : cpu cores   : 2
(单个物理CPU的逻辑CPU数)siblings is : siblings        : 2
[root@testhost ~]# 
  • 扩展
  1. 查看系统是多少位
[root@testhost ~]# uname -a
Linux testhost 3.10.0-862.14.4.el7.x86_64 #1 SMP Wed Sep 26 15:12:11 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

说明:i386 i686为32位;x86_64为64位

  1. 查看CPU是32位还是64位
[root@testhost ~]# cat /proc/cpuinfo | grep lm
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx rdtscp lm constant_tsc arch_perfmon nopl xtopology tsc_reliable nonstop_tsc eagerfpu pni pclmulqdq ssse3 cx16 sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer aes hypervisor lahf_lm tsc_adjust arat
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx rdtscp lm constant_tsc arch_perfmon nopl xtopology tsc_reliable nonstop_tsc eagerfpu pni pclmulqdq ssse3 cx16 sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer aes hypervisor lahf_lm tsc_adjust arat
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx rdtscp lm constant_tsc arch_perfmon nopl xtopology tsc_reliable nonstop_tsc eagerfpu pni pclmulqdq ssse3 cx16 sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer aes hypervisor lahf_lm tsc_adjust arat
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx rdtscp lm constant_tsc arch_perfmon nopl xtopology tsc_reliable nonstop_tsc eagerfpu pni pclmulqdq ssse3 cx16 sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer aes hypervisor lahf_lm tsc_adjust arat

说明:lm: “Long Mode,” which means the chip supports the AMD64 instruction set

你可能感兴趣的:(Linux)