Skip to main content
added 837 characters in body
Source Link
Kiwy
  • 9.9k
  • 13
  • 51
  • 81

AccordingConlusion:
If you don't want to read the whole explanation just read this:
Yes the value contained in /proc/[PID]/stat allows to determine the amount of CPU time used by a process and its children.
However, you can't use it for real time monitoring because value for children CPU time is updated only when child process die.

Explanation:
According to the man time time returns the following stats :

EDIT:
I though it was over but after doing some more researchAfter futher testing and talk wqith people, I tried the same with the command stressfinally get an answer, I've run a script that simply contains:

#!/bin/bash
sleep 5
time stress --cpu 4 -t 60s  
stress: info: [18598] dispatching hogs: 4 cpu, 0 io, 0 --vm, 0 hdd
stress: info: [18598] successful run completed in 60s
real    1m0,003s
user   -hang 3m53,663s15
sys    sleep 0m0,349s5

During the execution I watch 2 times/second the result of the command:

cat /proc/11223$$/stat | cut -d ' ' -f 14-17
0 0 0 0exit

WhileAnd using watch to monitor the metric in ps faux | grep stress/proc/$$/stat would give me this particular PIDat the same time. As long as father of the fourchild process is not finished the counter are not updated. When stress threadends then the value displayed in /proc/$$/stat are updated and ends with similar result between time command and the column 14 to 17 of /proc.

Conlusion:Old edit Short answer no it not cumulative not even consistent at least from my observation.

I though it was over but after doing some more research I tried the same with the command stress

time stress --cpu 4 -t 60s  
stress: info: [18598] dispatching hogs: 4 cpu, 0 io, 0 vm, 0 hdd
stress: info: [18598] successful run completed in 60s
real    1m0,003s
user    3m53,663s
sys     0m0,349s

During the execution I watch 2 times/second the result of the command:

cat /proc/11223/stat | cut -d ' ' -f 14-17
0 0 0 0

While ps faux | grep stress would give me this particular PID as father of the four stress thread.

According to the man time time returns the following stats :

EDIT:
I though it was over but after doing some more research I tried the same with the command stress

time stress --cpu 4 -t 60s  
stress: info: [18598] dispatching hogs: 4 cpu, 0 io, 0 vm, 0 hdd
stress: info: [18598] successful run completed in 60s
real    1m0,003s
user    3m53,663s
sys     0m0,349s

During the execution I watch 2 times/second the result of the command:

cat /proc/11223/stat | cut -d ' ' -f 14-17
0 0 0 0

While ps faux | grep stress would give me this particular PID as father of the four stress thread.

Conlusion: Short answer no it not cumulative not even consistent at least from my observation.

Conlusion:
If you don't want to read the whole explanation just read this:
Yes the value contained in /proc/[PID]/stat allows to determine the amount of CPU time used by a process and its children.
However, you can't use it for real time monitoring because value for children CPU time is updated only when child process die.

Explanation:
According to the man time time returns the following stats :

EDIT:
After futher testing and talk wqith people, I finally get an answer, I've run a script that simply contains:

#!/bin/bash
sleep 5
time stress --cpu 4 -t 60s --vm-hang 15
sleep 5
cat /proc/$$/stat | cut -d ' ' -f 14-17
exit

And using watch to monitor the metric in /proc/$$/stat at the same time. As long as the child process is not finished the counter are not updated. When stress ends then the value displayed in /proc/$$/stat are updated and ends with similar result between time command and the column 14 to 17 of /proc.

Old edit I though it was over but after doing some more research I tried the same with the command stress

time stress --cpu 4 -t 60s  
stress: info: [18598] dispatching hogs: 4 cpu, 0 io, 0 vm, 0 hdd
stress: info: [18598] successful run completed in 60s
real    1m0,003s
user    3m53,663s
sys     0m0,349s

During the execution I watch 2 times/second the result of the command:

cat /proc/11223/stat | cut -d ' ' -f 14-17
0 0 0 0

While ps faux | grep stress would give me this particular PID as father of the four stress thread.

added 684 characters in body
Source Link
Kiwy
  • 9.9k
  • 13
  • 51
  • 81

EDIT:
I though it was over but after doing some more research I tried the same with the command stress

time stress --cpu 4 -t 60s  
stress: info: [18598] dispatching hogs: 4 cpu, 0 io, 0 vm, 0 hdd
stress: info: [18598] successful run completed in 60s
real    1m0,003s
user    3m53,663s
sys     0m0,349s

During the execution I watch 2 times/second the result of the command:

cat /proc/11223/stat | cut -d ' ' -f 14-17
0 0 0 0

While ps faux | grep stress would give me this particular PID as father of the four stress thread.

Conlusion: Short answer no it not cumulative not even consistent at least from my observation.

EDIT:
I though it was over but after doing some more research I tried the same with the command stress

time stress --cpu 4 -t 60s  
stress: info: [18598] dispatching hogs: 4 cpu, 0 io, 0 vm, 0 hdd
stress: info: [18598] successful run completed in 60s
real    1m0,003s
user    3m53,663s
sys     0m0,349s

During the execution I watch 2 times/second the result of the command:

cat /proc/11223/stat | cut -d ' ' -f 14-17
0 0 0 0

While ps faux | grep stress would give me this particular PID as father of the four stress thread.

Conlusion: Short answer no it not cumulative not even consistent at least from my observation.

/proc/PID/stat’s time columns are the same on all Linux systems
Source Link
Stephen Kitt
  • 481.5k
  • 60
  • 1.2k
  • 1.4k

Et voilà, the CPU time is not exactly cumulative but you can calculate pretty accuratly (centisecond) the CPU time use by your program and it's children using /proc/[PID]/stat. You should of course try to adapt to your version of proc as this may vary from one one distro to another.

Et voilà, the CPU time is not exactly cumulative but you can calculate pretty accuratly (centisecond) the CPU time use by your program and it's children using /proc/[PID]/stat. You should of course try to adapt to your version of proc as this may vary from one one distro to another.

Et voilà, the CPU time is not exactly cumulative but you can calculate pretty accuratly (centisecond) the CPU time use by your program and it's children using /proc/[PID]/stat.

deleted 3 characters in body
Source Link
Kiwy
  • 9.9k
  • 13
  • 51
  • 81
Loading
Source Link
Kiwy
  • 9.9k
  • 13
  • 51
  • 81
Loading