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


In reply to Re: Using Perl to find Process Hogs by Limbic~Region
in thread Using Perl to find Process Hogs by Octavian

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.