Ubuntu -- 下如何查看CPU信息, 包括位數和多核信息


from: http://hi.baidu.com/sdusoul/blog/item/76f349508f74fb6e843524eb.html

查看當前操作系統內核信息
# 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

 

 

查看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顆數

# cat /proc/cpuinfo | grep physical | uniq -c

2 physical id    : 0
(說明實際上是1顆2核的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關鍵詞出現次數即可。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM