Linux下如何查看CPU型號、個數、核數、邏輯CPU數、位數、發行版本、內核信息、內存、服務器生產廠家

【原文鏈接】:http://blog.csdn.net/mdx20072419/article/details/7767809

 

# 總核數 = 物理CPU個數 X 每顆物理CPU的核數 
# 總邏輯CPU數 = 物理CPU個數 X 每顆物理CPU的核數 X 超線程數

# 查看物理CPU個數
cat /proc/cpuinfo| grep "physical id"| sort| uniq| wc -l

# 查看每個物理CPU中core的個數(即核數)
cat /proc/cpuinfo| grep "cpu cores"| uniq

# 查看邏輯CPU的個數
cat /proc/cpuinfo| grep "processor"| wc -l

 

 查看CPU信息(型號)
cat /proc/cpuinfo | grep name | cut -f2 -d: | uniq -c

 

查看內 存信息
# cat /proc/meminfo

 

-------------------------------------------------------------------------------------------------------------------------------------------------------------

 

查看邏輯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 "core id" /proc/cpuinfo|sort -u|wc -l                   
8

 

查看每個物理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內核數   沒有開啓超線程

 

一次性查詢所有信息:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

#!/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
*****************************

 

 

-------------------------------------------------------------------------------------------------------------------------------------------------------------

查看當前操作系統內核信息
# uname -a

 

Linux redcat 2.6.31-20-generic #58-Ubuntu SMP Fri Mar 12 05:23:09 UTC 2010 i686 GNU/Linux

 

查看當前操作系統發行版信息

 

#cat /etc/issue
Ubuntu 9.10 /n /l

 

1) 登錄到服務器執行 lsb_release -a ,即可列出所有版本信息,例如:

chen@mylinuxserver:/proc> lsb_release -a
LSB Version:    core-2.0-noarch:core-3.0-noarch:core-2.0-ia32:core-3.0-ia32:graphics-2.0-ia32:graphics-2.0-noarch:graphics-3.0-ia32:graphics-3.0-noarch
Distributor ID: SUSE LINUX
Description:    SUSE LINUX Enterprise Server 9 (i586)
Release:        9
Codename:       n/a

注:這個命令適用於所有的linux,包括Redhat、SuSE、Debian等發行版。

 

 

 

查看cpu型號

 

# cat /proc/cpuinfo | grep name | cut -f2 -d: | uniq -c
2  Intel(R) Core(TM)2 Duo CPU     P8600  @ 2.40GHz
(看到有2個邏輯CPU, 也知道了CPU型號)

 

查看cpu運行模式

# getconf LONG_BIT

32

(說明當前CPU運行在32bit模式下, 但不代表CPU不支持64bit)

 

 

查看cpu是否支持64bit

# cat /proc/cpuinfo | grep flags | grep ' lm ' | wc -l

2

(結果大於0, 說明支持64bit計算. lm指long mode, 支持lm則是64bit)

 

查看cpu信息概要(昨天看aix的時候剛發現的,在ubuntu上竟然也有~):

#lscpu

Architecture:          i686                            #架構686
CPU(s):                2                                   #邏輯cpu顆數是2
Thread(s) per core:    1                           #每個核心線程數是1                 
Core(s) per socket:    2                           #每個cpu插槽核數/每顆物理cpu核數是2
CPU socket(s):         1                            #cpu插槽數是1
Vendor ID:             GenuineIntel           #cpu廠商ID是GenuineIntel
CPU family:            6                              #cpu系列是6
Model:                 23                                #型號23
Stepping:              10                              #步進是10
CPU MHz:               800.000                 #cpu主頻是800MHz
Virtualization:        VT-x                         #cpu支持的虛擬化技術VT-x(對此在下一博文中解釋下http://hi.baidu.com/sdusoul/blog/item/5d8e0488def3a998a5c272c0.html)
L1d cache:             32K                         #一級緩存32K(google了下,這具體表示表示cpu的L1數據緩存爲32k)
L1i cache:             32K                          #一級緩存32K(具體爲L1指令緩存爲32K)
L2 cache:              3072K                      #二級緩存3072K
 

最後來個大而全的:

#cat /proc/cpuinfo

processor    : 0
vendor_id    : GenuineIntel
cpu family    : 6
model        : 23
model name    : Intel(R) Core(TM)2 Duo CPU     P8600  @ 2.40GHz
stepping    : 10
cpu MHz        : 800.000
cache size    : 3072 KB
physical id    : 0
siblings    : 2
core id        : 0
cpu cores    : 2
apicid        : 0
initial apicid    : 0
fdiv_bug    : no
hlt_bug        : no
f00f_bug    : no
coma_bug    : no
fpu        : yes
fpu_exception    : yes
cpuid level    : 13
wp        : yes
flags        : fpu vme de pse tsc msr pae mce cx8 apic mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe nx lm constant_tsc arch_perfmon pebs bts pni dtes64 monitor ds_cpl vmx smx est tm2 ssse3 cx16 xtpr pdcm sse4_1 xsave lahf_lm ida tpr_shadow vnmi flexpriority
bogomips    : 4788.60
clflush size    : 64
power management:

processor    : 1
vendor_id    : GenuineIntel
cpu family    : 6
model        : 23
model name    : Intel(R) Core(TM)2 Duo CPU     P8600  @ 2.40GHz
stepping    : 10
cpu MHz        : 800.000
cache size    : 3072 KB
physical id    : 0
siblings    : 2
core id        : 1
cpu cores    : 2
apicid        : 1
initial apicid    : 1
fdiv_bug    : no
hlt_bug        : no
f00f_bug    : no
coma_bug    : no
fpu        : yes
fpu_exception    : yes
cpuid level    : 13
wp        : yes
flags        : fpu vme de pse tsc msr pae mce cx8 apic mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe nx lm constant_tsc arch_perfmon pebs bts pni dtes64 monitor ds_cpl vmx smx est tm2 ssse3 cx16 xtpr pdcm sse4_1 xsave lahf_lm ida tpr_shadow vnmi flexpriority
bogomips    : 4787.96
clflush size    : 64
power management:

 

補充,linux下通過c獲取CPU個數信息

from: http://hi.baidu.com/hermitinhistory/blog/item/ce64d5fb6b23b71b6d22eb95.html

#include<stdio.h>
#include<unistd.h>

int main()
{
int cpu_num;

cpu_num = sysconf(_SC_NPROCESSORS_CONF);
printf("_SC_NPROCESSORS_CONF=%d/n",cpu_num);

cpu_num = sysconf(_SC_NPROCESSORS_ONLN);
printf("_SC_NPROCESSORS_ONLN=%d/n",cpu_num);

return 0;
}

/* 
* - _SC_NPROCESSORS_CONF
*       The number of processors configured.

* - _SC_NPROCESSORS_ONLN
*       The number of processors currently online (available).
*/


Linux下獲得CPU個數一個簡單方法就是查看/proc/cpuinfo文件。看出現processor字樣的行數是多少條,即有多少個邏輯CPU(包括多核,超線程)。
因此cmd下輸入下面命令即可:
cat /proc/cpuinfo | grep processor | wc -l
因此c++程序中很自然的想到使用strstr函數查找processor關鍵詞出現次數即可。

 

查看服務器型號(或者是生產廠家):
      #dmidecode | grep "Product Name"  
      Product Name: PowerEdge R710
      Product Name: 0VWN1R

 

	#dmidecode -t system

 

 


查看網卡信息:
      #dmesg | grep -i eth 
      Broadcom NetXtreme II Gigabit Ethernet Driver bnx2 v1.9.3 (March 17, 2009)
      eth0: Broadcom NetXtreme II BCM5709 1000Base-T (C0) PCI Express found at mem d6000000, IRQ 106, node addr a4badb28c33d
      eth1: Broadcom NetXtreme II BCM5709 1000Base-T (C0) PCI Express found at mem d8000000, IRQ 114, node addr a4badb28c33f
      eth2: Broadcom NetXtreme II BCM5709 1000Base-T (C0) PCI Express found at mem da000000, IRQ 122, node addr a4badb28c341
      eth3: Broadcom NetXtreme II BCM5709 1000Base-T (C0) PCI Express found at mem dc000000, IRQ 130, node addr a4badb28c343
      cnic: Added CNIC device: eth0
      cnic: Added CNIC device: eth1
      cnic: Added CNIC device: eth2
      cnic: Added CNIC device: eth3
      bnx2: eth0: using MSIX
      ADDRCONF(NETDEV_UP): eth0: link is not ready
      bnx2i: iSCSI not supported, dev=eth0
      bnx2i: iSCSI not supported, dev=eth0
      bnx2: eth0 NIC Copper Link is Up, 1000 Mbps full duplex
      ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready
      eth0: no IPv6 routers present
      process `sysctl' is using deprecated sysctl (syscall) net.ipv6.neigh.eth0.base_reachable_time; Usenet.ipv6.neigh.eth0.base_reachable_time_ms instead.

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章