探討Linux/proc檔案系統/proc directories,/proc files)
在 linux 檔案系統下 /proc 這個目錄,我們可以看到兩種類型的內容 -
一種是數字編號的目錄 , 另一種是與系統資訊相關的檔案 .
事實上 /proc 不不是一個實體的檔案系統而是虛擬的 . 其明顯例子就是當你
執行 # ls -l /proc/stat 指令時 , 你會注意到它顯示的檔案大小是 0 bytes , 但是你執行 #cat /proc/stat , 你卻可以看到這個檔案的內容 .
而有幾個 linux 的系統指令輸出結果 , 事實上它就是從 /proc 讀取資訊 ,
然後以某種格式呈現出來的 .
1.先來說說第一種依數字編號的目錄
當你執行 # ls -l /proc , 你會看到很多以數字為名的目錄 , 這些數字實際代表的是系統正運行的 process ids , 也就是程序編號 , 而相對應的目錄裡
所存放的檔案也就對應為該 PID 的程序所有.
下面列出的就是每個程序對應編號目錄裡所包含的重要檔案:
-
-
cmdline – command line of the command. 指令列
-
environ – environment variables.
環境參數
-
fd – Contains the file descriptors which is linked to the appropriate files.
連結到特定檔案的描述資訊
-
limits – Contains the information about the specific limits to the process.
程序的特別限制資訊
-
mounts – mount related information
掛載資訊
-
而其中所包含的重要連結有:
-
cwd – Link to current working directory of the process. 程序目前所在工作目錄
-
exe – Link to executable of the process. 程序的執行檔連結
-
root – Link to the root directory of the process. 根目錄的連結
2. 第二種就是 /proc 底下關於系統資訊的檔案, 例如:
-
/proc/cpuinfo – 關於 CPU的資訊
-
/proc/meminfo – 關於記憶體的資訊
-
/proc/loadvg – 附載資訊
-
/proc/partitions – 磁碟分割狀態資訊
-
/proc/version – linux 版本資訊
因此linux 某些系統檔案 ,就從/proc目錄底下讀取所需資訊,然後顯示出來,
例如 free 這個指令 , 它會從 /proc/meminfo 檔案讀出資訊 , 然後有格式的顯示出來 .
想了解更多個別 /proc 底下檔案所代表的含意,可以執行 'man 5 FILENAME'