Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

The Sys::Info approach as suggested by sflitman looks cool although I've never tried it myself.

As Windows is only 'possible future' and for the sake of TIMTOWTDI, run man top on one of your Un*x boxes and have a look at the -b option: batch mode. You could always call this from within Perl and then use the output however you wish.

I am not an expert at making system calls from within Perl so can't advise which of the various methods would suit this best. If you run top with -n 1 (only iterate once), I'd guess any of them should work. It's when you've got recurring output that things would get a bit more complicated. Of course, you could always call top -b from a shell script and have it piping to Perl.

But I'd still say that Sys::Info would be best ;-)

Update - forgot to say that you should probably check the man page for top on your target platforms just in case flags differ. Having just checked on the other (not Linux) OS I have here - FreeBSD - I note that the -n flag has a different meaning. So much for standardisation.

In reply to Re: How to Monitor System Resources by smiffy
in thread How to Monitor System Resources by barns

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    and the monks are mute...

    How do I use this? | Other CB clients
    Other Users?
    Others having an uproarious good time at the Monastery: (8)
    As of 2017-12-15 17:20 GMT
    Find Nodes?
      Voting Booth?
      What programming language do you hate the most?

      Results (439 votes). Check out past polls.