chishanmingshen 发表于 2014-12-01 15:16

cpu统计时间疑问。。。。

本帖最后由 chishanmingshen 于 2014-12-01 15:41 编辑

cat /proc/pid/stat:

cutime=0 累计的该任务的所有的waited-for进程曾经在用户态运行的时间,单位为jiffies
cstime=0 累计的该任务的所有的waited-for进程曾经在核心态运行的时间,单位为jiffies

里面2个字段,网上描述如上,但是不懂。。。请指点,谢谢!

请指点,谢谢!

Tinnal 发表于 2014-12-01 23:52

回复 1# chishanmingshen


(14) utime%lu
                        Amount of time that this process has been scheduled
                        in user mode, measured in clock ticks (divide by
                        sysconf(_SC_CLK_TCK)).This includes guest time,
                        guest_time (time spent running a virtual CPU, see
                        below), so that applications that are not aware of
                        the guest time field do not lose that time from
                        their calculations.

            (15) stime%lu
                        Amount of time that this process has been scheduled
                        in kernel mode, measured in clock ticks (divide by
                        sysconf(_SC_CLK_TCK)).

            (16) cutime%ld
                        Amount of time that this process's waited-for
                        children have been scheduled in user mode, measured
                        in clock ticks (divide by sysconf(_SC_CLK_TCK)).
                        (See also times(2).)This includes guest time,
                        cguest_time (time spent running a virtual CPU, see
                        below).

            (17) cstime%ld
                        Amount of time that this process's waited-for
                        children have been scheduled in kernel mode,
                        measured in clock ticks (divide by
                        sysconf(_SC_CLK_TCK)).

就是被wait for的子进程所花掉的用户态时间和内核态时间呀。和utime、stime的差别是,前者记录的是小孩的,后者记录的是自己的。 waited-for children 应该是指我们在父进程调用wait 函数所等待的子进程的意思(见下面的man说明)。
cutime不仅仅出现在proc接口里,更重要的也是times系统调用的输出(http://linux.die.net/man/2/times), 为什么要提times?估计你用过time吧(http://linux.die.net/man/1/time)。很经典的一个命令,估计cutime是为它而生的。
页: [1]
查看完整版本: cpu统计时间疑问。。。。