On 11/19/05, Anders Norrbring
I don't understand a diff I get in outputs from 'top' and ps', can somebody please explain it?
If I run 'ps -A -o %cpu,%mem,comm' and grep for 'httpd', I get 0.0% CPU time. If I run top at the same time, I get 13.9% cpu load for httpd2-prefork.
ps and top express "cpu" differently. While ps calculates it by "total CPU time" divided by "time task is running" top shows the value as a percentage of overall CPU time. For ps it means: the longer a process is running without a high CPU utilization the smaller the value of %cpu gets (it converges to zero). It is different from top that displays this value as share of the CPU time since last screen update and is therefore more accurate in terms of "current CPU utilization". \Steve Thanks Steve! Is there a good way to get the 'top' values in a query similar to the ps command I tried to use? 'ps -A -o %cpu,comm' What I'm looking for is the cpu load value at the very moment I ask for it, no averages. Anders.
On 11/19/05, Anders Norrbring
On 11/19/05, Anders Norrbring
wrote: I don't understand a diff I get in outputs from 'top' and ps', can somebody please explain it?
If I run 'ps -A -o %cpu,%mem,comm' and grep for 'httpd', I get 0.0% CPU time. If I run top at the same time, I get 13.9% cpu load for httpd2-prefork.
ps and top express "cpu" differently. While ps calculates it by "total CPU time" divided by "time task is running" top shows the value as a percentage of overall CPU time. For ps it means: the longer a process is running without a high CPU utilization the smaller the value of %cpu gets (it converges to zero). It is different from top that displays this value as share of the CPU time since last screen update and is therefore more accurate in terms of "current CPU utilization".
\Steve
Thanks Steve! Is there a good way to get the 'top' values in a query similar to the ps command I tried to use? 'ps -A -o %cpu,comm'
Unfortunately not, at least not easily. Some grep and awk magic will
do it, but I'm to lazy right now to provide a solution (something like
"ps -ef | grep <name> > `awk -F { print $0 } -' ").
\Steve
--
Steve Graegert
On 11/19/05, Steve Graegert
On 11/19/05, Anders Norrbring
wrote: On 11/19/05, Anders Norrbring
wrote: I don't understand a diff I get in outputs from 'top' and ps', can somebody please explain it?
If I run 'ps -A -o %cpu,%mem,comm' and grep for 'httpd', I get 0.0% CPU time. If I run top at the same time, I get 13.9% cpu load for httpd2-prefork.
ps and top express "cpu" differently. While ps calculates it by "total CPU time" divided by "time task is running" top shows the value as a percentage of overall CPU time. For ps it means: the longer a process is running without a high CPU utilization the smaller the value of %cpu gets (it converges to zero). It is different from top that displays this value as share of the CPU time since last screen update and is therefore more accurate in terms of "current CPU utilization".
\Steve
Thanks Steve! Is there a good way to get the 'top' values in a query similar to the ps command I tried to use? 'ps -A -o %cpu,comm'
Unfortunately not, at least not easily. Some grep and awk magic will do it, but I'm to lazy right now to provide a solution (something like "ps -ef | grep <name> > `awk -F { print $0 } -' ").
OK, sorry, this command is useless forgot to integrate top running in
batch mode:
'top -cbn1 p<pid from awk>'.
\Steve
--
Steve Graegert
On 2005-11-19 17:27 Steve Graegert wrote:
On 11/19/05, Steve Graegert
wrote: On 11/19/05, Anders Norrbring
wrote: On 11/19/05, Anders Norrbring
wrote: I don't understand a diff I get in outputs from 'top' and ps', can somebody please explain it?
If I run 'ps -A -o %cpu,%mem,comm' and grep for 'httpd', I get 0.0% CPU time. If I run top at the same time, I get 13.9% cpu load for httpd2-prefork.
ps and top express "cpu" differently. While ps calculates it by "total CPU time" divided by "time task is running" top shows the value as a percentage of overall CPU time. For ps it means: the longer a process is running without a high CPU utilization the smaller the value of %cpu gets (it converges to zero). It is different from top that displays this value as share of the CPU time since last screen update and is therefore more accurate in terms of "current CPU utilization".
\Steve
Thanks Steve! Is there a good way to get the 'top' values in a query similar to the ps command I tried to use? 'ps -A -o %cpu,comm'
Unfortunately not, at least not easily. Some grep and awk magic will do it, but I'm to lazy right now to provide a solution (something like "ps -ef | grep <name> > `awk -F { print $0 } -' ").
OK, sorry, this command is useless forgot to integrate top running in batch mode: 'top -cbn1 p<pid from awk>'.
Thanks for the idea.. :) Didn't realize that top had a batch mode. It seems like "top -bn1 | grep httpd | awk '{a+=$9} END {print a}'" works just fine! -- Anders Norrbring Norrbring Consulting
On 11/19/05, Anders Norrbring
On 2005-11-19 17:27 Steve Graegert wrote:
On 11/19/05, Steve Graegert
wrote: On 11/19/05, Anders Norrbring
wrote: On 11/19/05, Anders Norrbring
wrote: I don't understand a diff I get in outputs from 'top' and ps', can somebody please explain it?
If I run 'ps -A -o %cpu,%mem,comm' and grep for 'httpd', I get 0.0% CPU time. If I run top at the same time, I get 13.9% cpu load for httpd2-prefork.
ps and top express "cpu" differently. While ps calculates it by "total CPU time" divided by "time task is running" top shows the value as a percentage of overall CPU time. For ps it means: the longer a process is running without a high CPU utilization the smaller the value of %cpu gets (it converges to zero). It is different from top that displays this value as share of the CPU time since last screen update and is therefore more accurate in terms of "current CPU utilization".
\Steve
Thanks Steve! Is there a good way to get the 'top' values in a query similar to the ps command I tried to use? 'ps -A -o %cpu,comm'
Unfortunately not, at least not easily. Some grep and awk magic will do it, but I'm to lazy right now to provide a solution (something like "ps -ef | grep <name> > `awk -F { print $0 } -' ").
OK, sorry, this command is useless forgot to integrate top running in batch mode: 'top -cbn1 p<pid from awk>'.
Thanks for the idea.. :) Didn't realize that top had a batch mode. It seems like "top -bn1 | grep httpd | awk '{a+=$9} END {print a}'" works just fine!
Cool. That's the awk sequence I was thinking about but did not find.
No, I'm still not good at sed/awk :-)
\Steve
--
Steve Graegert
participants (2)
-
Anders Norrbring
-
Steve Graegert