linux proc/pid/stat解析

proc/pid/stat用于获取某一个进程的统计信息,实现过程见fs/proc/array.c的do_task_stat()

1. stat数据

$ adb shell cat /proc/8385/stat
1557 (system_server) S 823 823 0 0 -1 1077952832 //1~9
2085481 15248 2003 27 166114 129684 26 30  //10~17
10 -10 221 0 2284 2790821888 93087 18446744073709551615 //18~25
1 1 0 0 0 0 6660 0 36088 0 0 0 17 3 0 0 0 0 0 0 0 0 0 0 0 0 0

2. 解释

1 pid: 进程ID.
2 comm: task_struct结构体的进程名
3 state: 进程状态, 此处为S
4 ppid: 父进程ID (父进程是指通过fork方式,通过clone并非父进程)
5 pgrp:进程组ID
6 session:进程会话组ID
7 tty_nr:当前进程的tty终点设备号
8 tpgid:控制进程终端的前台进程号
9 flags:进程标识位,定义在include/linux/sched.h中的PF_*, 此处等于1077952832
10 minflt: 次要缺页中断的次数,即无需从磁盘加载内存页. 比如COW和匿名页
11 cminflt:当前进程等待子进程的minflt
12 majflt:主要缺页中断的次数,需要从磁盘加载内存页. 比如map文件
13 majflt:当前进程等待子进程的majflt
14 utime: 该进程处于用户态的时间,单位jiffies,此处等于166114
15 stime: 该进程处于内核态的时间,单位jiffies,此处等于129684
16 cutime:当前进程等待子进程的utime
17 cstime: 当前进程等待子进程的utime
18 priority: 进程优先级, 此次等于10.
19 nice: nice值,取值范围[19, -20],此处等于-10
20 num_threads: 线程个数, 此处等于221
21 itrealvalue: 该字段已废弃,恒等于0
22 starttime:自系统启动后的进程创建时间,单位jiffies,此处等于2284
23 vsize:进程的虚拟内存大小,单位为bytes
24 rss: 进程独占内存+共享库,单位pages,此处等于93087
25 rsslim: rss大小上限

3. 说明:

第10~17行主要是随着时间而改变的量;
内核时间单位,sysconf(_SC_CLK_TCK)一般地定义为jiffies(一般地等于10ms)
starttime: 此值单位为jiffies, 结合/proc/stat的btime,可知道每一个线程启动的时间点, 1500827856 + 2284/100 = 1500827856, 转换成北京时间为2017/7/24 0:37:58
第四行数据很少使用,只说一下该行第7至9个数的含义:

signal:即将要处理的信号,十进制,此处等于6660
blocked:阻塞的信号,十进制
sigignore:被忽略的信号,十进制,此处等于36088

  • 5
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
The /proc/PID/stat file contains various statistics about the process with the specified PID. The file is a single line of text, with each field separated by a space. The fields in the file are as follows: 1. pid - process ID 2. comm - name of the command that started the process 3. state - current state of the process (e.g. running, sleeping, etc.) 4. ppid - parent process ID 5. pgrp - process group ID 6. session - session ID 7. tty_nr - controlling terminal of the process 8. tpgid - ID of the foreground process group of the controlling terminal 9. flags - process flags (e.g. whether it is being traced, etc.) 10. minflt - number of minor faults (i.e. page faults that could be resolved without disk IO) 11. cminflt - number of minor faults of child processes 12. majflt - number of major faults (i.e. page faults that required disk IO) 13. cmajflt - number of major faults of child processes 14. utime - amount of time the process has spent in user mode 15. stime - amount of time the process has spent in kernel mode 16. cutime - amount of time waited-for children have been in user mode 17. cstime - amount of time waited-for children have been in kernel mode 18. priority - priority of the process 19. nice - nice value of the process 20. num_threads - number of threads in the process 21. starttime - time the process started, in jiffies (1/100th of a second) 22. vsize - virtual memory size of the process 23. rss - resident set size of the process (i.e. amount of physical memory it is using) 24. rsslim - current limit on the resident set size 25. startcode - address of the start of the code segment 26. endcode - address of the end of the code segment 27. startstack - address of the start of the stack 28. kstkesp - current value of the stack pointer 29. kstkeip - current value of the instruction pointer 30. signal - bitmap of pending signals for the process 31. blocked - bitmap of blocked signals for the process 32. sigignore - bitmap of ignored signals for the process 33. sigcatch - bitmap of caught signals for the process 34. wchan - address of the kernel function the process is currently waiting in 35. nswap - number of pages swapped to disk 36. cnswap - number of pages swapped to disk of child processes 37. exit_signal - signal to be sent to the parent process when the process exits 38. processor - CPU the process last ran on 39. rt_priority - real-time priority of the process 40. policy - scheduling policy of the process Note: Some fields may be displayed as 0 if they are not applicable to the process or if they are not available. Also, the values for utime, stime, cutime, and cstime are given in clock ticks, which can be converted to seconds by dividing by the value of the system variable HZ (which is typically 100 on most systems).
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值