On 04/09/2019 13:50, Adam Majer wrote:
On 9/4/19 12:49 PM, Carlos E. R. wrote:
On 04/09/2019 12.29, Carlos E. R. wrote:
"top" must obtain the data from somewhere. I want to obtain the same data top does, with calling another program. If there is no other way, I'll use top and parse the output.
Once (2014) I started to write a "top" equivalent, but only went as far as the header. I parsed /proc/stat, but my notes do not say where I obtained the definition of that file and I do not remember.
/proc/pid/stat output seems to be in do_task_stat() function in fs/proc/array.c. And you are looking at the utime and stime part for usermode and kernel execution time. So looks like position 14 and 15 respectfully.
awk '{print $14 , "user time;", $15, "kernel time"}' stat
Columns 14-17 appears to be information returned in the `man 2 times` call, the other two numbers are for child tasks.
documented in proc(5) - man 5 proc and see /proc/[pid]/stat . And in repsonse to Basil's suggestion, using ksysguard mightn't be the bad idea, if he meant using the source, as it certainly uses usertime and systime to calculate the process' CPU utilisation as a percentage. There's a detailed discussion of techniques here, too: https://stackoverflow.com/questions/16726779/how-do-i-get-the-total-cpu-usag... Will <submerges again> -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org