in reply to Using Perl to find Process Hogs

Octavian,
I am not sure of another HPUX utility that calculates the CPU utilization percentage on the fly like top does. Since you are being tasked to do this, I am betting this is the value they want you to use.

#!/usr/bin/perl -w use strict; unlink "/tmp/prochogs.$$" if (-e "/tmp/prochogs.$$"); system ("top -u -h -d1 -s1 -f /tmp/prochogs.$$"); open (TOP,"/tmp/prochogs.$$") or die "Unable to open top file - $!"; my %Proc; my $FoundList; while (<TOP>) { if (/^CPU/) { $FoundList = 1; next; } next unless ($FoundList); my @Values = split; $Proc{$Values[2]} = \@Values; } foreach(keys %Proc) { print "$_ : $Proc{$_}->[11]\n"; }

So why write the output to a file and read it back in instead of creating a pipe? Well, when run interactively, top on HPUX formats the output with a bunch of ANSI escape sequences that is a pain to parse.

This should give you what you want and is easy to modify. You want to make sure your temporary file makes sense on your system.

Cheers - L~R