歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> Linux調優之分析 /proc

Linux調優之分析 /proc

日期:2017/2/28 14:43:13   编辑:Linux教程

先來了解下什麼是/proc

Linux 內核提供了一種通過 /proc 文件系統,在運行時訪問內核內部數據結構、 改變內核設置的機制。

/proc 是一個虛擬的文件系統:

/proc 文件系統是一種內核和內核模塊用來向進程 (process) 發送信息的機制 (所以叫做 /proc)。這個偽文件系統讓你可以和內核內部數據結構進行交互,獲取 有關進程的有用信息,在運行中 (on the fly) 改變設置 (通過改變內核參數)。 與其他文件系統不同,/proc 存在於內存之中而不是硬盤上。如果你察看文件 /proc/mounts (和 mount 命令一樣列出所有已經加載的文件系統),你會看到其中 一行是這樣的:

[root@localhost ~]# grep proc /proc/mounts

proc /procproc rw,relatime 0 0

/proc 是由內核控制的,所以沒有所謂掛載proc的設備,/proc主要是存放內核控制的狀態信息,所以大部分這些信息的邏輯位置位於內核控制的內存。對 /proc 進行 一次 'ls -l' 可以看到大部分文件都是 0 字節大的;不過察看這些文件的時候,確 實可以看到一些信息。這怎麼可能?這是因為 /proc 文件系統和其他常規的文件系 統一樣把自己注冊到虛擬文件系統層 (VFS) 了。然而,直到當 VFS 調用它,請求 文件、目錄的 i-node 的時候,/proc 文件系統才根據內核中的信息建立相應的文件和目錄。

查看/proc 文件系統, 我們可以通過如:“cat”、“less”、“more”等命令來查看,當然了可以配合一些管道命令有如“grep”、“awk”、“sed”等來選取數據

當編輯程序試圖打開一個虛擬文件時,這個文件就通過內核 中的信息被憑空地 (on the fly) 創建了。這是一些我從我的系統中得到的一些有趣 結果:

cpu信息文件 "/proc/cpuinfo"

執行cat查看:

[root@localhost proc]# cat /proc/cpuinfo
processor: 0
vendor_id: GenuineIntel
cpu family: 6
model: 58
model name: Intel(R) Core(TM) i7-3632QM CPU @ 2.20GHz
stepping: 9
cpu MHz: 2195.013
cache size: 6144 KB
physical id: 0
siblings: 3
core id: 0
cpu cores: 3
apicid: 0
initial apicid: 0
fpu: yes
fpu_exception: yes
cpuid level: 13
wp: yes
flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts mmx fxsr sse sse2 ss ht syscall nx rdtscp lm constant_tsc arch_perfmon pebs bts xtopology tsc_reliable nonstop_tsc aperfmperf unfair_spinlock pni pclmulqdq ssse3 cx16 sse4_1 sse4_2 popcnt aes xsave avx hypervisor lahf_lm ida arat epb xsaveopt pln pts dts
bogomips: 4390.02
clflush size: 64
cache_alignment: 64
address sizes: 40 bits physical, 48 bits virtual
power management:
processor: 1
vendor_id: GenuineIntel
cpu family: 6
model: 58
model name: Intel(R) Core(TM) i7-3632QM CPU @ 2.20GHz
stepping: 9
cpu MHz: 2195.013
cache size: 6144 KB
physical id: 0
siblings: 3
core id: 1
cpu cores: 3
apicid: 1
initial apicid: 1
fpu: yes
fpu_exception: yes
cpuid level: 13
wp: yes
flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts mmx fxsr sse sse2 ss ht syscall nx rdtscp lm constant_tsc arch_perfmon pebs bts xtopology tsc_reliable nonstop_tsc aperfmperf unfair_spinlock pni pclmulqdq ssse3 cx16 sse4_1 sse4_2 popcnt aes xsave avx hypervisor lahf_lm ida arat epb xsaveopt pln pts dts
bogomips: 4390.02
clflush size: 64
cache_alignment: 64
address sizes: 40 bits physical, 48 bits virtual
power management:
processor: 2
vendor_id: GenuineIntel
cpu family: 6
model: 58
model name: Intel(R) Core(TM) i7-3632QM CPU @ 2.20GHz
stepping: 9
cpu MHz: 2195.013
cache size: 6144 KB
physical id: 0
siblings: 3
core id: 2
cpu cores: 3
apicid: 2
initial apicid: 2
fpu: yes
fpu_exception: yes
cpuid level: 13
wp: yes
flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts mmx fxsr sse sse2 ss ht syscall nx rdtscp lm constant_tsc arch_perfmon pebs bts xtopology tsc_reliable nonstop_tsc aperfmperf unfair_spinlock pni pclmulqdq ssse3 cx16 sse4_1 sse4_2 popcnt aes xsave avx hypervisor lahf_lm ida arat epb xsaveopt pln pts dts
bogomips: 4390.02
clflush size: 64
cache_alignment: 64
address sizes: 40 bits physical, 48 bits virtual
power management:
processor: 3
vendor_id: GenuineIntel
cpu family: 6
model: 58
model name: Intel(R) Core(TM) i7-3632QM CPU @ 2.20GHz
stepping: 9
cpu MHz: 2195.013
cache size: 6144 KB
physical id: 1
siblings: 3
core id: 0
cpu cores: 3
apicid: 4
initial apicid: 4
fpu: yes
fpu_exception: yes
cpuid level: 13
wp: yes
flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts mmx fxsr sse sse2 ss ht syscall nx rdtscp lm constant_tsc arch_perfmon pebs bts xtopology tsc_reliable nonstop_tsc aperfmperf unfair_spinlock pni pclmulqdq ssse3 cx16 sse4_1 sse4_2 popcnt aes xsave avx hypervisor lahf_lm ida arat epb xsaveopt pln pts dts
bogomips: 4390.02
clflush size: 64
cache_alignment: 64
address sizes: 40 bits physical, 48 bits virtual
power management:
processor: 4
vendor_id: GenuineIntel
cpu family: 6
model: 58
model name: Intel(R) Core(TM) i7-3632QM CPU @ 2.20GHz
stepping: 9
cpu MHz: 2195.013
cache size: 6144 KB
physical id: 1
siblings: 3
core id: 1
cpu cores: 3
apicid: 5
initial apicid: 5
fpu: yes
fpu_exception: yes
cpuid level: 13
wp: yes
flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts mmx fxsr sse sse2 ss ht syscall nx rdtscp lm constant_tsc arch_perfmon pebs bts xtopology tsc_reliable nonstop_tsc aperfmperf unfair_spinlock pni pclmulqdq ssse3 cx16 sse4_1 sse4_2 popcnt aes xsave avx hypervisor lahf_lm ida arat epb xsaveopt pln pts dts
bogomips: 4390.02
clflush size: 64
cache_alignment: 64
address sizes: 40 bits physical, 48 bits virtual
power management:
processor: 5
vendor_id: GenuineIntel
cpu family: 6
model: 58
model name: Intel(R) Core(TM) i7-3632QM CPU @ 2.20GHz
stepping: 9
cpu MHz: 2195.013
cache size: 6144 KB
physical id: 1
siblings: 3
core id: 2
cpu cores: 3
apicid: 6
initial apicid: 6
fpu: yes
fpu_exception: yes
cpuid level: 13
wp: yes
flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts mmx fxsr sse sse2 ss ht syscall nx rdtscp lm constant_tsc arch_perfmon pebs bts xtopology tsc_reliable nonstop_tsc aperfmperf unfair_spinlock pni pclmulqdq ssse3 cx16 sse4_1 sse4_2 popcnt aes xsave avx hypervisor lahf_lm ida arat epb xsaveopt pln pts dts
bogomips: 4390.02
clflush size: 64
cache_alignment: 64
address sizes: 40 bits physical, 48 bits virtual
power management:

上述大部分的信息十分清楚地給出了這個系 統的有用的硬件信息。有些 /proc 的文件是經過編碼的,不同的工具可以被用來解釋 這些編碼過的信息並輸出成可讀的形式。這樣的工具包括:'top', 'ps', 'apm' 等。

更多詳情見請繼續閱讀下一頁的精彩內容: http://www.linuxidc.com/Linux/2013-10/90934p2.htm

Copyright © Linux教程網 All Rights Reserved