LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   PS command capturing CPU (https://www.linuxquestions.org/questions/linux-newbie-8/ps-command-capturing-cpu-642744/)

jr8rdt 05-16-2008 04:15 PM

PS command capturing CPU
 
I want to capture the cpu utilization of a process.
so I write a small script using this command

ps -o pid,pcpu <PID>

it does give me the cpu util for that pid however the number is different from TOP (irix on). the number from TOP is more accurate. since I have dual core cpu , how can I make the "ps" command works ?

thanks

aus9 05-16-2008 08:04 PM

don't use irix but try
Code:

ps aux
to get a bigger range of pids

syg00 05-16-2008 08:39 PM

Quote:

Originally Posted by jr8rdt (Post 3155688)
it does give me the cpu util for that pid however the number is different from TOP (irix on). the number from TOP is more accurate. since I have dual core cpu , how can I make the "ps" command works ?

Noooo ...
The number from "top" is a different metric to that presented by "ps". Neither is necessarily more accurate than the other, given that /proc is the source of the data used by both.

Read the man pages, then decide what it really is you are trying to measure.

jr8rdt 05-17-2008 08:08 PM

the program that I am tracking is a single threaded program. does that mean pcpu is more accurate ?
I do have quad dual core CPU (4 @dual core).

I read somewhere that pcpu is for the whole machine ie a CPU hog(100%) on a 4 CPU machine would register as 25%. Is this correct? So why then in my case , pcpu gives 75% and top irix on gives 25%?
What I want is a total CPU percentage.just like the description of pcpu I found on the net
Could you please help me understand ?

btw is there a command or switch to turn on irix mode in top if I want to use batch?

thanks


All times are GMT -5. The time now is 04:35 AM.