cutime 和 cstime jiffies 是否也包括子进程?
Do the cutime and cstime jiffies include the child processes as well?
在文件 /proc/[PID]/stat
中,值 cutime
和 cstime
(该文件的第 14 和 15 个元素)是带有子元素的 jiffies,这是否意味着进程的子元素?
int cutime; /** user mode jiffies with childs **/
int cstime; /** kernel mode jiffies with childs **/
这是否意味着 jiffies 也包括进程的子进程?
cutime 和 cstime 的含义记录在 man 5 proc
cutime
Amount of time that this process’s waited-for children have been scheduled in user mode, measured in clock ticks...
cstime
Amount of time that this process’s waited-for children have been scheduled in kernel mode, measured in clock ticks...
utime
和 stime
测量 CPU 进程创建的 children 时间。
cutime
和 cstime
是进程创建的所有 children(及其 children...)的 CPU 次之和.不包括utime
和stime
这个过程,只是children时间。
请注意,当进程使用 CPU 时,utime
和 ctime
会在线更新,但是 child 时会更新 cutime
和 cstime
] 退出,进程为此 child.
调用 wait
编辑 - @txs 的实验,因为 @txs 不相信:
显示进程统计信息的简单脚本:
$ cat ./procstat.sh 6668
while sleep 1
do
cat /proc//stat | awk '{ print "utime:", , "stime:", , "cutime:" , "cstime:", }'
done
两个终端,一个正在运行ning脚本,另一个执行耗时处理。我测量了一个 bash 过程。我在测量bash中开始了一个无限循环。 utime 不断增加。然后我中断了循环并开始了 child bash 进程和 运行 child 进程中的无限循环。什么都没有改变,但是当我中断进程并退出 child bash 时,cutime 立即改变了。
$ ps +
PID TTY TIME CMD |
10178 pts/2 00:00:00 bash |
10197 pts/2 00:00:00 ps |
| $ ./procstat.sh 10178
| utime: 2 stime: 1 cutime:1 cstime: 3
| utime: 2 stime: 1 cutime:1 cstime: 3
| utime: 2 stime: 1 cutime:1 cstime: 3
| utime: 3 stime: 1 cutime:1 cstime: 3
| utime: 3 stime: 1 cutime:1 cstime: 3
| utime: 3 stime: 1 cutime:1 cstime: 3
$ while true; do true; done | utime: 49 stime: 1 cutime:1 cstime: 3
| utime: 137 stime: 1 cutime:1 cstime: 3
| utime: 209 stime: 1 cutime:1 cstime: 3
| utime: 296 stime: 1 cutime:1 cstime: 3
| utime: 391 stime: 1 cutime:1 cstime: 3
^C | utime: 477 stime: 1 cutime:1 cstime: 3
| utime: 521 stime: 1 cutime:1 cstime: 3
| utime: 521 stime: 1 cutime:1 cstime: 3
| utime: 521 stime: 1 cutime:1 cstime: 3
$ bash | utime: 522 stime: 1 cutime:1 cstime: 3
| utime: 522 stime: 1 cutime:1 cstime: 3
| utime: 522 stime: 1 cutime:1 cstime: 3
| utime: 522 stime: 1 cutime:1 cstime: 3
$ while true; do true; done | utime: 522 stime: 1 cutime:1 cstime: 3
| utime: 522 stime: 1 cutime:1 cstime: 3
| utime: 522 stime: 1 cutime:1 cstime: 3
| utime: 522 stime: 1 cutime:1 cstime: 3
| utime: 522 stime: 1 cutime:1 cstime: 3
^C | utime: 522 stime: 1 cutime:1 cstime: 3
| utime: 522 stime: 1 cutime:1 cstime: 3
| utime: 522 stime: 1 cutime:1 cstime: 3
$ exit | utime: 522 stime: 1 cutime:623 cstime: 6
| utime: 522 stime: 1 cutime:623 cstime: 6
| utime: 522 stime: 1 cutime:623 cstime: 6
| utime: 522 stime: 1 cutime:623 cstime: 6
+ utime: 522 stime: 1 cutime:623 cstime: 6
在文件 /proc/[PID]/stat
中,值 cutime
和 cstime
(该文件的第 14 和 15 个元素)是带有子元素的 jiffies,这是否意味着进程的子元素?
int cutime; /** user mode jiffies with childs **/
int cstime; /** kernel mode jiffies with childs **/
这是否意味着 jiffies 也包括进程的子进程?
cutime 和 cstime 的含义记录在 man 5 proc
cutime
Amount of time that this process’s waited-for children have been scheduled in user mode, measured in clock ticks...
cstime
Amount of time that this process’s waited-for children have been scheduled in kernel mode, measured in clock ticks...
utime
和 stime
测量 CPU 进程创建的 children 时间。
cutime
和 cstime
是进程创建的所有 children(及其 children...)的 CPU 次之和.不包括utime
和stime
这个过程,只是children时间。
请注意,当进程使用 CPU 时,utime
和 ctime
会在线更新,但是 child 时会更新 cutime
和 cstime
] 退出,进程为此 child.
wait
编辑 - @txs 的实验,因为 @txs 不相信:
显示进程统计信息的简单脚本:
$ cat ./procstat.sh 6668
while sleep 1
do
cat /proc//stat | awk '{ print "utime:", , "stime:", , "cutime:" , "cstime:", }'
done
两个终端,一个正在运行ning脚本,另一个执行耗时处理。我测量了一个 bash 过程。我在测量bash中开始了一个无限循环。 utime 不断增加。然后我中断了循环并开始了 child bash 进程和 运行 child 进程中的无限循环。什么都没有改变,但是当我中断进程并退出 child bash 时,cutime 立即改变了。
$ ps +
PID TTY TIME CMD |
10178 pts/2 00:00:00 bash |
10197 pts/2 00:00:00 ps |
| $ ./procstat.sh 10178
| utime: 2 stime: 1 cutime:1 cstime: 3
| utime: 2 stime: 1 cutime:1 cstime: 3
| utime: 2 stime: 1 cutime:1 cstime: 3
| utime: 3 stime: 1 cutime:1 cstime: 3
| utime: 3 stime: 1 cutime:1 cstime: 3
| utime: 3 stime: 1 cutime:1 cstime: 3
$ while true; do true; done | utime: 49 stime: 1 cutime:1 cstime: 3
| utime: 137 stime: 1 cutime:1 cstime: 3
| utime: 209 stime: 1 cutime:1 cstime: 3
| utime: 296 stime: 1 cutime:1 cstime: 3
| utime: 391 stime: 1 cutime:1 cstime: 3
^C | utime: 477 stime: 1 cutime:1 cstime: 3
| utime: 521 stime: 1 cutime:1 cstime: 3
| utime: 521 stime: 1 cutime:1 cstime: 3
| utime: 521 stime: 1 cutime:1 cstime: 3
$ bash | utime: 522 stime: 1 cutime:1 cstime: 3
| utime: 522 stime: 1 cutime:1 cstime: 3
| utime: 522 stime: 1 cutime:1 cstime: 3
| utime: 522 stime: 1 cutime:1 cstime: 3
$ while true; do true; done | utime: 522 stime: 1 cutime:1 cstime: 3
| utime: 522 stime: 1 cutime:1 cstime: 3
| utime: 522 stime: 1 cutime:1 cstime: 3
| utime: 522 stime: 1 cutime:1 cstime: 3
| utime: 522 stime: 1 cutime:1 cstime: 3
^C | utime: 522 stime: 1 cutime:1 cstime: 3
| utime: 522 stime: 1 cutime:1 cstime: 3
| utime: 522 stime: 1 cutime:1 cstime: 3
$ exit | utime: 522 stime: 1 cutime:623 cstime: 6
| utime: 522 stime: 1 cutime:623 cstime: 6
| utime: 522 stime: 1 cutime:623 cstime: 6
| utime: 522 stime: 1 cutime:623 cstime: 6
+ utime: 522 stime: 1 cutime:623 cstime: 6