in reply to Running 'top' command (of linux) for few minutes and then come out of system command (of perl)

G'day Striker,

I have a different version of top (with different options) so I can't test this. However, looking at this top manpage (which appears to have the same options that you're using), I'd guess you can add a -n iterations to your top command; then put a sleep between the system statements.

So, with a delay of 5 seconds, that would be 36 iterations in 3 minutes:

system "top -p 1758 -b -d5 -n36 | tee -a stats.log"; sleep 180; system "./top_stats.sh -f stats.log";

According to that manpage, top should stop running after the set number of iterations, so you won't need a Ctrl-C (or equivalent).

-- Ken

  • Comment on Re: Running 'top' command (of linux) for few minutes and then come out of system command (of perl)
  • Select or Download Code

Replies are listed 'Best First'.
Re^2: Running 'top' command (of linux) for few minutes and then come out of system command (of perl)
by robby_dobby (Hermit) on Mar 19, 2014 at 09:32 UTC
    ++! Now that you mention it, I remember using -n for running top through 'n' iterations of page refresh. There's also the 'batch mode' for passing output from top to other programs. Here's what my copy of manpage has to say about this:
    -b : Batch mode operation
                Starts  top  in 'Batch mode', which could be useful for sending output from top to other programs
                or to a file.  In this mode, top will not accept input and runs until the iterations limit you've
                set with the '-n' command-line option or until killed.