/proc文件系統(二):/proc/<pid>/stat【轉】

轉自:https://www.cnblogs.com/Jimmy1988/p/10045601.html

0. 前言

/proc 文件系統是一個僞文件系統,它只存在內存當中,而不佔用外存空間。

  • 它以文件系統的方式爲內核與進程提供通信的接口。用戶和應用程序可以通過/proc得到系統的信息,並可以改變內核的某些參數。
  • 由於系統的信息,如進程,是動態改變的,所以用戶或應用程序讀取/proc目錄中的文件時,proc文件系統是動態從系統內核讀出所需信息並提交的。
  root@jimmy-vm:/proc# ll /proc/
  dr-xr-xr-x 9 root root 0 11月 28 20:09 <pid>/
  ......
  dr-xr-xr-x 2 root root 0 11月 30 16:53 acpi/
  dr-xr-xr-x 5 root root 0 11月 30 16:53 asound/
  -r--r--r-- 1 root root 0 11月 30 16:53 buddyinfo
  dr-xr-xr-x 4 root root 0 11月 30 16:53 bus/
  -r--r--r-- 1 root root 0 11月 30 16:53 cgroups
  -r--r--r-- 1 root root 0 11月 30 16:53 cmdline
  -r--r--r-- 1 root root 0 11月 30 16:53 consoles
  -r--r--r-- 1 root root 0 11月 30 16:53 cpuinfo
  -r--r--r-- 1 root root 0 11月 30 16:53 crypto
  -r--r--r-- 1 root root 0 11月 30 16:53 devices
  -r--r--r-- 1 root root 0 11月 30 16:53 diskstats
  -r--r--r-- 1 root root 0 11月 30 16:53 dma
  dr-xr-xr-x 2 root root 0 11月 30 16:53 driver/
  -r--r--r-- 1 root root 0 11月 30 16:53 execdomains
  -r--r--r-- 1 root root 0 11月 30 16:53 fb
  -r--r--r-- 1 root root 0 11月 30 16:53 filesystems
  dr-xr-xr-x 5 root root 0 11月 30 16:53 fs/
  -r--r--r-- 1 root root 0 11月 30 16:53 interrupts
  -r--r--r-- 1 root root 0 11月 30 16:53 iomem
  -r--r--r-- 1 root root 0 11月 30 16:53 ioports
  dr-xr-xr-x 57 root root 0 11月 30 16:53 irq/
  -r--r--r-- 1 root root 0 11月 30 16:53 kallsyms
  -r-------- 1 root root 140737477881856 11月 30 16:53 kcore
  -r--r--r-- 1 root root 0 11月 30 16:53 keys
  -r--r--r-- 1 root root 0 11月 30 16:53 key-users
  -r-------- 1 root root 0 11月 16 14:27 kmsg
  -r-------- 1 root root 0 11月 30 16:53 kpagecgroup
  -r-------- 1 root root 0 11月 30 16:53 kpagecount
  -r-------- 1 root root 0 11月 30 16:53 kpageflags
  -r--r--r-- 1 root root 0 11月 30 16:53 loadavg
  -r--r--r-- 1 root root 0 11月 30 16:53 locks
  -r--r--r-- 1 root root 0 11月 30 16:53 mdstat
  -r--r--r-- 1 root root 0 11月 30 16:53 meminfo
  -r--r--r-- 1 root root 0 11月 30 16:53 misc
  -r--r--r-- 1 root root 0 11月 30 16:53 modules
  lrwxrwxrwx 1 root root 11 11月 30 16:53 mounts -> self/mounts
  dr-xr-xr-x 3 root root 0 11月 30 16:53 mpt/
  -rw-r--r-- 1 root root 0 11月 30 16:53 mtrr
  lrwxrwxrwx 1 root root 8 11月 30 16:53 net -> self/net/
  -r--r--r-- 1 root root 0 11月 30 16:53 pagetypeinfo
  -r--r--r-- 1 root root 0 11月 30 16:53 partitions
  -r--r--r-- 1 root root 0 11月 30 16:53 sched_debug
  -r--r--r-- 1 root root 0 11月 30 16:53 schedstat
  dr-xr-xr-x 4 root root 0 11月 30 16:53 scsi/
  lrwxrwxrwx 1 root root 0 11月 16 14:27 self -> 107692/
  -r-------- 1 root root 0 11月 30 16:53 slabinfo
  -r--r--r-- 1 root root 0 11月 30 16:53 softirqs
  -r--r--r-- 1 root root 0 11月 30 16:53 stat
  -r--r--r-- 1 root root 0 11月 16 14:27 swaps
  dr-xr-xr-x 1 root root 0 11月 16 14:27 sys/
  --w------- 1 root root 0 11月 30 16:53 sysrq-trigger
  dr-xr-xr-x 2 root root 0 11月 30 16:53 sysvipc/
  lrwxrwxrwx 1 root root 0 11月 16 14:27 thread-self -> 107692/task/107692/
  -r--r--r-- 1 root root 0 11月 30 16:53 timer_list
  -rw-r--r-- 1 root root 0 11月 30 16:53 timer_stats
  dr-xr-xr-x 4 root root 0 11月 30 16:53 tty/
  -r--r--r-- 1 root root 0 11月 30 16:53 uptime
  -r--r--r-- 1 root root 0 11月 30 16:53 version
  -r--r--r-- 1 root root 0 11月 30 16:53 version_signature
  -r-------- 1 root root 0 11月 30 16:53 vmallocinfo
  -r--r--r-- 1 root root 0 11月 30 16:53 vmstat
  -r--r--r-- 1 root root 0 11月 30 16:53 zoneinfo
   

1. /proc/cpuinfo

/proc文件系統(一):cpuinfo

2. /proc/<pid> 整體

/proc目錄中有一些以數字命名的目錄,它們是進程目錄。

  • 系統中當前運行的每一個進程在/proc下都對應一個以進程號爲目錄名的目錄/proc/pid,它們是讀取進程信息的接口。
  • 在Linux 2.6.0-test6以上的版本中/proc/pid目錄中有一個task目錄,/proc/pid/task目錄中也有一些以該進程所擁有的線程的線程號命名的目錄/proc/pid/task/tid,它們是讀取線程信息的接口。

pid_list

  root@TinaLinux:/proc/219# ll
  dr-xr-xr-x 8 root root 0 Nov 30 14:49 .
  dr-xr-xr-x 1031 root root 0 Jan 1 1970 ..
  dr-xr-xr-x 2 root root 0 Nov 30 14:52 attr
  -r-------- 1 root root 0 Nov 30 14:49 auxv
  -r--r--r-- 1 root root 0 Nov 30 14:49 cmdline
  -rw-r--r-- 1 root root 0 Nov 30 14:52 comm
  -rw-r--r-- 1 root root 0 Nov 30 14:52 coredump_filter
  lrwxrwxrwx 1 root root 0 Nov 30 14:52 cwd -> /usr/bvrobot
  -r-------- 1 root root 0 Nov 30 14:52 environ
  lrwxrwxrwx 1 root root 0 Nov 30 14:49 exe -> /usr/bvrobot/bvrobot
  dr-x------ 2 root root 0 Nov 30 14:52 fd
  dr-x------ 2 root root 0 Nov 30 14:52 fdinfo
  -r--r--r-- 1 root root 0 Nov 30 14:52 limits
  -rw-r--r-- 1 root root 0 Nov 30 14:52 loginuid
  -r--r--r-- 1 root root 0 Nov 30 14:52 maps
  -rw------- 1 root root 0 Nov 30 14:52 mem
  -r--r--r-- 1 root root 0 Nov 30 14:52 mountinfo
  -r--r--r-- 1 root root 0 Nov 30 14:52 mounts
  -r-------- 1 root root 0 Nov 30 14:52 mountstats
  dr-xr-xr-x 4 root root 0 Nov 30 14:52 net
  dr-x--x--x 2 root root 0 Nov 30 14:52 ns
  -rw-r--r-- 1 root root 0 Nov 30 14:52 oom_adj
  -r--r--r-- 1 root root 0 Nov 30 14:52 oom_score
  -rw-r--r-- 1 root root 0 Nov 30 14:52 oom_score_adj
  -r--r--r-- 1 root root 0 Nov 30 14:52 personality
  lrwxrwxrwx 1 root root 0 Nov 30 14:52 root -> /
  -r--r--r-- 1 root root 0 Nov 30 14:52 sessionid
  -r--r--r-- 1 root root 0 Nov 30 14:52 stack
  -r--r--r-- 1 root root 0 Nov 30 14:49 stat
  -r--r--r-- 1 root root 0 Nov 30 14:52 statm
  -r--r--r-- 1 root root 0 Nov 30 14:52 status
  dr-xr-xr-x 13 root root 0 Nov 30 14:52 task
  -r--r--r-- 1 root root 0 Nov 30 14:52 wchan

2.1 /proc/<pid>/stat

  root@TinaLinux:/proc/3782# cat stat
  3782 (bvrobot) S 114 3782 114 64512 4072 1077936384 8727 14959 0 0 37 524 0 1 20 0 11 0 71083 45535232 8490 4294967295 65536 1285064 3201052128 3201049428 3069071928 0 0 4096 67137026 4294967295 0 0 17 2 0 0 0 0 0 1353712 1360302 4616192
參數數值解釋
pid 3782 進程(包括輕量級進程,即線程)號
comm bvrobot 應用程序或命令的名字
task_state S 任務的狀態:
R:runnign, S:sleeping (TASK_INTERRUPTIBLE),
T: stopped, Z:zombie, D:dead
ppid 114 父進程ID
pgid 3782 進程組號
sid 114 該任務所在的會話組ID
tty_nr 64512(pts/6) 該任務的tty終端的設備號
tty_pgrp 4072 終端的進程組號,當前運行在該任務所在終端的前臺任務(包括shell 應用程序)的PID。
task->flags 1077936384 進程標誌位,查看該任務的特性
min_flt 8727 該任務不需要從硬盤拷數據而發生的缺頁(次缺頁)的次數
cmin_flt 14959 累計的該任務的所有的waited-for進程曾經發生的次缺頁的次數目
maj_flt 0 該任務需要從硬盤拷數據而發生的缺頁(主缺頁)的次數
cmaj_flt 0 累計的該任務的所有的waited-for進程曾經發生的主缺頁的次數目
utime 37 該任務在用戶態運行的時間,單位爲jiffies
stime 524 該任務在覈心態運行的時間,單位爲jiffies
cutime 0 累計的該任務的所有的waited-for進程曾經在用戶態運行的時間,單位爲jiffies
cstime 1 累計的該任務的所有的waited-for進程曾經在覈心態運行的時間,單位爲jiffies
priority 20 任務的動態優先級
nice 0 任務的靜態優先級
num_threads 11 該任務所在的線程組裏線程的個數
it_real_value 0 由於計時間隔導致的下一個 SIGALRM 發送進程的時延,以 jiffy 爲單位.
start_time 71038 該任務啓動的時間,單位爲jiffies
vsize 45535232 該任務的虛擬地址空間大小
rss 8490 該任務當前駐留物理地址空間的大小;。
rlim 4294967295 該任務能駐留物理地址空間的最大值
start_code 65536 該任務在虛擬地址空間的代碼段的起始地址
end_code 1285064 該任務在虛擬地址空間的代碼段的結束地址
start_stack 3201052128 該任務在虛擬地址空間的棧的結束地址
kstkesp 3201049428 esp(32 位堆棧指針) 的當前值, 與在進程的內核堆棧頁得到的一致.
kstkeip 3069071928 指向將要執行的指令的指針, EIP(32 位指令指針)的當前值.
pendingsig 0 待處理信號的位圖,記錄發送給進程的普通信號
block_sig 0 阻塞信號的位圖
sigign 4096 忽略的信號的位圖
sigcatch 67137026 被俘獲的信號的位圖
wchan 4294967295 如果該進程是睡眠狀態,該值給出調度的調用點
nswap 0 被swapped的頁數,當前沒用
cnswap 0 所有子進程被swapped的頁數的和,當前沒用
exit_signal 17 該進程結束時,向父進程所發送的信號
task_cpu(task) 2 運行在哪個CPU上
task_rt_priority 0 實時進程的相對優先級別
task_policy 0 進程的調度策略,0:非實時進程,1:FIFO實時進程;2:RR實時進程
blio_ticks 0 等待阻塞IO的時間
gtime 1353712 guest time of the task in jiffies
cgtime 1360302 guest time of the task children in jiffies
start_data 4616192 address above which program data+bss is placed
end_data   address below which program data+bss is placed
start_brk   address above which program heap can be expanded with br
  arg_start | | address above which program command line is placed

arg_end | | address below which program command line is placed
env_start | | address above which program environment is placed
env_end | | address below which program environment is placed
exit_code | | the thread's exit_code in the form reported by the waitpid system call

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章