關(guān)于Linux文件目錄/proc

一句話總結(jié)

通過(guò)strace命令跟蹤可知,經(jīng)常使用的ps、top、free等命令都是通過(guò)讀/proc目錄下的文件獲得數(shù)據(jù)然后加以處理和展示。/proc目錄是procfs文件系統(tǒng)的掛載點(diǎn),procfs作為內(nèi)核中數(shù)據(jù)結(jié)構(gòu)的訪問(wèn)接口,提供系統(tǒng)的運(yùn)行時(shí)信息。

strace跟蹤

free -m命令會(huì)讀文件/proc/meminfo,示例如下:

# strace free -m 2>&1 | grep "/proc/meminfo"
open("/proc/meminfo", O_RDONLY)         = 4

lscpu命令會(huì)讀文件/proc/cpuinfo/sys/devices/system/cpu/目錄下的文件。

pstop命令會(huì)讀/proc/sys/kernel/pid_max/proc/$pid/{stat, status, cmdline}等文件。

還有很多其它的命令在此不再贅述,感興趣的話用strace跟蹤一下命令的執(zhí)行即可。

/proc介紹

在此引用相關(guān)文檔的解釋和說(shuō)明,感興趣的同學(xué)可根據(jù)對(duì)應(yīng)文檔深入了解。

https://github.com/torvalds/linux/blob/master/Documentation/filesystems/proc.txt

The proc file system acts as an interface to internal data structures in the
kernel. It can be used to obtain information about the system and to change
certain kernel parameters at runtime (sysctl).

http://www.tldp.org/LDP/Linux-Filesystem-Hierarchy/html/proc.html

You might wonder how you can see details of a process that has a file size of 0. It makes more sense if you think of it as a window into the kernel. The file doesn't actually contain any data; it just acts as a pointer to where the actual process information resides.

man proc

The proc file system is a pseudo-file system which is used as an interface to kernel data structures. It is commonly mounted at /proc. Most of it is read-only, but some files allow kernel variables to be changed.

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • **2014真題Directions:Read the following text. Choose the be...
    又是夜半驚坐起閱讀 11,116評(píng)論 0 23
  • 很多時(shí)候,我們被輿論裹挾,去到一些地方,做一些事,當(dāng)時(shí)可能覺(jué)得熱血非常,但后來(lái)思考“那些事真的是那樣嗎?那么做真的...
    十二時(shí)辰閱讀 541評(píng)論 0 3
  • 遐思千里云天外,展翅八荒巨野開。 蕭瑟秋風(fēng)吹不盡,哀鴻遍地早霜白。 當(dāng)年恥辱今猶記,往日囂張豈再來(lái)。 崛起神州強(qiáng)勁...
    不惑而歌閱讀 250評(píng)論 35 28
  • 時(shí)間過(guò)得真快,90天的踐行結(jié)束了,有收獲,有反思。 收獲: 1、早睡早起。之前也會(huì)早睡早起,但早上起來(lái)就開始忙家務(wù)...
    xiaoluoer閱讀 259評(píng)論 0 0
  • 大家好,七點(diǎn)文書不在簡(jiǎn)書更新文章,有自己的微信公眾號(hào),想?yún)⑴c我們各種活動(dòng)和福利的,請(qǐng)關(guān)注微信號(hào)!
    七點(diǎn)wen書閱讀 191評(píng)論 0 0

友情鏈接更多精彩內(nèi)容