Greetings Monks, I know that this is a silly question, but we are pressed for time and I wanted to draw on your experience. So here are the details:

We are writing a test script as part of a porting effort. We need to perform the following:

Open a program and
1. read its STDOUT
2. calculate its system time
3. calculate its max memory
4. kill it if the script is Control-C'd

Here are the caveats: it has to be Unix/Win portable and can not use any non-core modules.

So, we use open(PROG,"pogname|") to open the program with a handle to its stdout. We install a signal-handler to deal with keyboard interupts. Fine. But how do we kill a program started by 'open' from the signal handler? Simply closing the filehandle is not enough.

To get the system time, we use 'times' as such:

($user,$system,$cuser,$csystem) = times;

It seems to me that the program started with 'open' should be our child, but $cuser & $csystem are zero. Does this only work when you have forked a child?

As for the max memory issue, I could scan the ps table, but this is not portable. I am at a loss here.

I know that this is actually several questions. I am also painfully aware that there is no easy answer, but I will be happy to consider any advise you might have to offer.

"Never take yourself too seriously, because everyone knows that fat birds dont fly" -FLC

In reply to Portable Process Control by scmason

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.