toma,
You are correct, Proc::ProcessTable does provide
a pctcpu option. There are a couple of reasons I
suggested parsing top instead of Proc::ProcessTable.
The first is because there is no way (that I know of) to change
the sampling window as there is with top. The second reason is
HPUX does not ship with an ANSI compliant C compiler. This isn't
a big obstacle to overcome, but for the sake of portability, I have
no issues parsing the output of a built-in command especially one
developed by the vendor.
With that said, here is some sample code on how it could be used:
(Much cleaner than my parsing of top)
#!/usr/bin/perl -w
use strict;
use Proc::ProcessTable;
my $t = new Proc::ProcessTable;
foreach my $proc ( @{$t->table} ){
print $proc->pid , " : " , $proc->pctcpu , "\n";
}
Cheers - L~R | [reply] [d/l] |
Yeah, I have seen ProcessTable talked about before, but its not found in our build of perl, so I assumed it was an extra module downloadable from CPAN...that is why I made mention that I couldnt use any extra stuff like that, only the built in stuff in the standard build of perl...
I would like to thank you though for your assistance, I am not sure how TOP calculates that %CPU stat, but that is the one that needs to be searched on. I was hoping for a special magic perl function that I didnt know about, but when trying out your snippet using top, it works pretty quick (alot faster than my attempt at using top) so it looks like that is the way to go for me.
Again, thank you for your wisdom!
| [reply] |