Linux下程式設計系統訊息之獲取

一、查看作業系統版本 

#  uname -a

Linux apps-test-game 
2.6 . 9 - 11 . ELsmp  # 1  SMP Fri May  20   18 : 26 : 27  EDT  2005  i686 i68
6  i386 GNU / Linux



#  cat /proc/version

Linux version 
2.6 . 9 - 11 . ELsmp  ( bhcompile@decompose . build . redhat . com )   ( gcc version
 
3.4 . 3   20050227   ( Red Hat  3.4 . 3 - 22 ))   # 1  SMP Fri May  20   18 : 26 : 27  EDT  2005



#  cat /etc/issue

Red Hat Enterprise Linux AS release 
4   ( Nahant Update  1 )
Kernel 
on  an  m



# cat /etc/redhat-release

Red Hat Enterprise Linux AS release 
4   ( Nahant Update  1 )

 

二、查看CPU

Linux下的CPU訊息放在/proc/cpuinfo文件中,這個文件里面記錄了許多詳細的訊息,可以用fopen打開它或者用popen執行一條cat命令來得到結果。

# cat /proc/cpuinfo
processor       : 
0
vendor_id       : GenuineIntel
cpu family      : 
15
model           : 
4
model name      : Intel
( R )  Xeon ( TM )  CPU  3 . 20GHz
stepping        : 
10
cpu MHz         : 
3200.847
cache  size      :  2048  KB
physical id     : 
0
siblings        : 
2
fdiv_bug        : no
hlt_bug         : no
f00f_bug        : no
coma_bug        : no
fpu             : yes
fpu_exception   : yes
cpuid level     : 
5
wp              : yes
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov
pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe nx lm pni monitor ds_c
pl cid xtpr
bogomips        : 
6275.07

processor       : 
1
vendor_id       : GenuineIntel
cpu family      : 
15
model           : 
4
model name      : Intel
( R )  Xeon ( TM )  CPU  3 . 20GHz
stepping        : 
10
cpu MHz         : 
3200.847
cache  size      :  2048  KB
physical id     : 
0
siblings        : 
2
fdiv_bug        : no
hlt_bug         : no
f00f_bug        : no
coma_bug        : no
fpu             : yes
fpu_exception   : yes
cpuid level     : 
5
wp              : yes
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov
pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe nx lm pni monitor ds_c
pl cid xtpr
bogomips        : 
6389.76

processor       : 
2
vendor_id       : GenuineIntel
cpu family      : 
15
model           : 
4
model name      : Intel
( R )  Xeon ( TM )  CPU  3 . 20GHz
stepping        : 
10
cpu MHz         : 
3200.847
cache  size      :  2048  KB
physical id     : 
3
siblings        : 
2
fdiv_bug        : no
hlt_bug         : no
f00f_bug        : no
coma_bug        : no
fpu             : yes
fpu_exception   : yes
cpuid level     : 
5
wp              : yes
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov
pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe nx lm pni monitor ds_c
pl cid xtpr
bogomips        : 
6389.76

processor       : 
3
vendor_id       : GenuineIntel
cpu family      : 
15
model           : 
4
model name      : Intel
( R )  Xeon ( TM )  CPU  3 . 20GHz
stepping        : 
10
cpu MHz         : 
3200.847
cache  size      :  2048  KB
physical id     : 
3
siblings        : 
2
fdiv_bug        : no
hlt_bug         : no
f00f_bug        : no
coma_bug        : no
fpu             : yes
fpu_exception   : yes
cpuid level     : 
5
wp              : yes
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov
pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe nx lm pni monitor ds_c
pl cid xtpr
bogomips        : 
6389.76

CPU的完整訊息。

# cat /proc/cpuinfo | grep processor | wc -l
4

CPU計數,有4個CPU(可能為2個雙核的)。

 

三、查看(記憶體)內存訊息

與CPU一樣,Linux下的記憶體訊息放在/proc/meminfo文件中,這個文件里面記錄了許多詳細的訊息,可以用fopen打開它或者用popen執行一條cat命令來得到結果。

比如:

#free
             total       used       free     shared    buffers     cached
Mem:       
1034148       846312       187836            0        57304       418236
-/+  buffers / cache:      370772       663376
Swap:      
2031608            0      2031608


或者:

#cat /proc/meminfo
MemTotal:      
1034148  kB
MemFree:        
188620  kB
Buffers:         
57312  kB
Cached:         
418228  kB
SwapCached:          
0  kB
Active:         
559084  kB
Inactive:       
226244  kB
HighTotal:      
130496  kB
HighFree:          
252  kB
LowTotal:       
903652  kB
LowFree:        
188368  kB
SwapTotal:     
2031608  kB
SwapFree:      
2031608  kB
Dirty:              
60  kB
Writeback:           
0  kB
Mapped:         
364944  kB
Slab:            
49184  kB
Committed_AS:   
487816  kB
PageTables:       
2832  kB
VmallocTotal:   
106488  kB
VmallocUsed:      
3504  kB
VmallocChunk:   
102648  kB
HugePages_Total:     
0
HugePages_Free:      
0
Hugepagesize:     
2048  kB
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值