There are many ways to do this but if you go with a
scraping ps method, you might want to try using the
-o switch which will simplify your parse step. Check the
man pages for the -o switch keywords. I just used
split instead of a regex:
@outrecs = `ps -efo pid,pcpu,fname`;
@matches = grep /ns-httpd/, @outrecs;
foreach (@matches) {
$ct++;
chomp;
($process, $pcpu, $pname) = split(" ");
$sttotal = $sttotal + $pcpu;
}
This is a snippet of real code in which I did use strict
(omitted in the example though). I also had a related
thread a while back with useful info. HTH.
--Jim
Update: You can also use:
@matches = `ps -efo pid,pcpu,fname|grep httpd`;
to eliminate the need for the Perl grep. Just realized that
after I posted. Learn something all the time. :)
|