Linux下如何查看CPU型号、个数、核数、逻辑CPU数、位数、发行版本、内核信息、内存、服务器生产厂家

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

http://blog.chinaunix.net/uid-22425237-id-3496577.html

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

# 总核数 = 物理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.


你可能感兴趣的:(linux,内核)