#!/usr/local/bin/perl use strict; my ($ct, $pcpu, $pname, $i, @outrecs, @matches, $process); my $MaxUtil = 70; my $sttotal = 0; my $ct = 0; foreach $i (1..5) { @outrecs = `ps -efo pid,pcpu,fname`; @matches = grep /ns-httpd/, @outrecs; ## Note: can have more than one ns-httpd running ## but we'll average it in as well foreach (@matches) { $ct++; chomp; ($process, $pcpu, $pname) = split(" "); $sttotal = $sttotal + $pcpu; } sleep(3); } my $pcpuavg = $sttotal / $ct;