Getting pcpu from ps command
807559Oct 14 2007 — edited Oct 15 2007I'm trying to get percentage CU over a larger period.
Here is what I get using the elapse time and cpu time formula.
(The format is pid, % CPU, virtual mem, mem, cpu time, elapsed time, args to the process)
ps -efo pid,pcpu,vsz,rss,time,etime,args | grep mypro
7620 18.3 361976 345400 07:37:45 12:25:23 mypro
(wait for some time)
ps -efo pid,pcpu,vsz,rss,time,etime,args | grep mypro
7620 18.2 361976 345400 07:37:50 12:25:30 mypro
The delta for elapsed time is 12:25:30 - 12:25:23 = 7 sec
The delta for CPU time is 07:37:50 - 07:37:45 = 5 sec.
The percentage CPU is 100*5/7 = 71 %
This appears to be 4x the number of CPUs.
I�m not finding any google to confirm this. Any help would be great!.
My problems are:
1. The figures given by pcpu (18.2 or 18.3%) doesn't match with the above calculation (71%) I would like to know if my formula is good :|
2. If the above formula has to do with the number of CPUs, can I get that within the ps command itself?
thanks,
-Vikrantl