In the file /proc/[PID]/stat
, the values cutime
and cstime
(14 and 15 elements of that file) are jiffies with childs, does that mean the childs of a process?
int cutime; /** user mode jiffies with childs **/
int cstime; /** kernel mode jiffies with childs **/
Does that mean the jiffies are also including the children of the process?
The cutime and cstime meaning is documented in 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
and stime
measure CPU time of the process without children that the process created.
cutime
and cstime
are sum of CPU times of all children (and their children...) that the process created. It does not include utime
and stime
of this process but children only time.
Note that utime
and ctime
are updated online when the process uses CPU but cutime
and cstime
are updated when a child exits and the process calls wait
for this child.
EDIT - an experiment for @txs because @txs does not believe:
Simple script for showing proc statistics:
$ cat ./procstat.sh 6668
while sleep 1
do
cat /proc/$1/stat | awk '{ print "utime:", $14, "stime:", $15, "cutime:" $16, "cstime:", $17 }'
done
Two terminals, one is running the script and the other one executes time consuming processing. I measured a bash process. I started an infinite loop in the measured bash. utime was constantly increased. Then I interrupted the loop and start a child bash process and run the infinite loop in child process. Nothing changed but the cutime was changed at once when I interrupted the process and exit the child bash.
$ 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