[opensuse] Can I find the percent of cpu load for a process in a script?
Hi, Can I find the percent of cpu load for a process inside a script? At worst, I can find it out from "top", but I wonder if there is a more direct way. I'm looking at "/proc/21500/stat" or "/proc/21500/statm", but I have no idea what each value is, where are those virtual files documented. -- Cheers / Saludos, Carlos E. R. (from 15.0 x86_64 at Telcontar)
On 4/9/19 6:38 pm, Carlos E. R. wrote:
Hi,
Can I find the percent of cpu load for a process inside a script?
At worst, I can find it out from "top", but I wonder if there is a more direct way.
I'm looking at "/proc/21500/stat" or "/proc/21500/statm", but I have no idea what each value is, where are those virtual files documented.
Won't KSysGuard do this for you? BC -- A three-year-old boy was examining his testicles while taking a bath. "Mum" he asked, "are these my brains?" "Not yet," she replied. -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org
On 04/09/2019 11.07, Basil Chupin wrote:
On 4/9/19 6:38 pm, Carlos E. R. wrote:
Hi,
Can I find the percent of cpu load for a process inside a script?
At worst, I can find it out from "top", but I wonder if there is a more direct way.
I'm looking at "/proc/21500/stat" or "/proc/21500/statm", but I have no idea what each value is, where are those virtual files documented.
Won't KSysGuard do this for you?
A GUI? Nope. I want the value inside a script, to do things with it. -- Cheers / Saludos, Carlos E. R. (from 15.0 x86_64 at Telcontar)
Carlos E. R. wrote:
Hi,
Can I find the percent of cpu load for a process inside a script?
At worst, I can find it out from "top", but I wonder if there is a more direct way.
run that process with 'time' ? -- Per Jessen, Zürich (17.3°C) http://www.hostsuisse.com/ - dedicated server rental in Switzerland. -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org
On 04/09/2019 11.08, Per Jessen wrote:
Carlos E. R. wrote:
Hi,
Can I find the percent of cpu load for a process inside a script?
At worst, I can find it out from "top", but I wonder if there is a more direct way.
run that process with 'time' ?
Nono. I want, in a script, to find the cpu load value of a different program, at many times. -- Cheers / Saludos, Carlos E. R. (from 15.0 x86_64 at Telcontar)
Carlos E. R. wrote:
On 04/09/2019 11.08, Per Jessen wrote:
Carlos E. R. wrote:
Hi,
Can I find the percent of cpu load for a process inside a script?
At worst, I can find it out from "top", but I wonder if there is a more direct way.
run that process with 'time' ?
Nono. I want, in a script, to find the cpu load value of a different program, at many times.
Yes, so run _that_ program with 'time'. -- Per Jessen, Zürich (18.1°C) http://www.cloudsuisse.com/ - your owncloud, hosted in Switzerland. -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org
Per Jessen wrote:
Carlos E. R. wrote:
On 04/09/2019 11.08, Per Jessen wrote:
Carlos E. R. wrote:
Hi,
Can I find the percent of cpu load for a process inside a script?
At worst, I can find it out from "top", but I wonder if there is a more direct way.
run that process with 'time' ?
Nono. I want, in a script, to find the cpu load value of a different program, at many times.
Yes, so run _that_ program with 'time'.
I.e. inside your script: #!/bin/bash do this do that time do more do something else do something entirely different. But I see you said "percent of cpu load" - what is that good for? -- Per Jessen, Zürich (18.4°C) http://www.dns24.ch/ - your free DNS host, made in Switzerland. -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org
On 04/09/2019 11.52, Per Jessen wrote:
Per Jessen wrote:
Carlos E. R. wrote:
On 04/09/2019 11.08, Per Jessen wrote:
Carlos E. R. wrote:
Hi,
Can I find the percent of cpu load for a process inside a script?
At worst, I can find it out from "top", but I wonder if there is a more direct way.
run that process with 'time' ?
Nono. I want, in a script, to find the cpu load value of a different program, at many times.
Yes, so run _that_ program with 'time'.
I.e. inside your script:
#!/bin/bash do this do that time do more do something else do something entirely different.
Again, no. That's the load at the end. I want to monitor a daemon, clamd, at any point. Instant CPU load. "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. -- Cheers / Saludos, Carlos E. R. (from 15.0 x86_64 at Telcontar)
On 04/09/2019 12.29, Carlos E. R. wrote:
On 04/09/2019 11.52, Per Jessen wrote:
Per Jessen wrote:
Again, no. That's the load at the end. I want to monitor a daemon, clamd, at any point. Instant CPU load.
"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. -- Cheers / Saludos, Carlos E. R. (from 15.0 x86_64 at Telcontar)
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. Have lots of fun, Adam -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org
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
On 04/09/2019 14.00, Will Stephenson wrote:
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>
Tank you for emerging :-) Yes, that's the information I needed. Thanks also to Dave and Adam :-) -- Cheers / Saludos, Carlos E. R. (from 15.0 x86_64 at Telcontar)
On Wed, 4 Sep 2019 12:49:10 +0200 "Carlos E. R." <robin.listas@telefonica.net> wrote:
On 04/09/2019 12.29, Carlos E. R. wrote:
On 04/09/2019 11.52, Per Jessen wrote:
Per Jessen wrote:
Again, no. That's the load at the end. I want to monitor a daemon, clamd, at any point. Instant CPU load.
"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.
Well, I just googled for /proc/stat and immediately found a definition :) More useful is man proc(5) which hints that /proc/<pid>/stat is probably what you want if you're coding it yourself. -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org
On Wed, 4 Sep 2019 12:29:38 +0200 "Carlos E. R." <robin.listas@telefonica.net> wrote:
On 04/09/2019 11.52, Per Jessen wrote:
Per Jessen wrote:
Carlos E. R. wrote:
On 04/09/2019 11.08, Per Jessen wrote:
Carlos E. R. wrote:
Hi,
Can I find the percent of cpu load for a process inside a script?
At worst, I can find it out from "top", but I wonder if there is a more direct way.
run that process with 'time' ?
Nono. I want, in a script, to find the cpu load value of a different program, at many times.
Yes, so run _that_ program with 'time'.
I.e. inside your script:
#!/bin/bash do this do that time do more do something else do something entirely different.
Again, no. That's the load at the end. I want to monitor a daemon, clamd, at any point. Instant CPU load.
"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.
What about `ps'? E.g.: steve [ ~ ]$ ps -q $(pidof emacs) -o pcpu,comm %CPU COMMAND 0.3 emacs Steve Berman -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org
On 09/04/2019 03:38 AM, Carlos E. R. wrote:
Hi,
Can I find the percent of cpu load for a process inside a script?
At worst, I can find it out from "top", but I wonder if there is a more direct way.
I'm looking at "/proc/21500/stat" or "/proc/21500/statm", but I have no idea what each value is, where are those virtual files documented.
How do I get the total CPU usage of an application from /proc/pid/stat? https://stackoverflow.com/questions/16726779/how-do-i-get-the-total-cpu-usag... -- David C. Rankin, J.D.,P.E.
participants (8)
-
Adam Majer
-
Basil Chupin
-
Carlos E. R.
-
Dave Howorth
-
David C. Rankin
-
Per Jessen
-
Stephen Berman
-
Will Stephenson