For timing out a spawned child see alarm and the working example in there.

For reading back the output of the child, why not make child write its output to a specified file, via a command line parameter, e.g. `child.exe -o out.123`, or `child.exe > out.123`. 123 could be child's pid. Problem with incomplete output if you timeout child, so add a marker at EOF indicating successful completion of process.

But you need to keep track of how many children are currently running because you don't want to overwhelm your system. And that additional requirement leads us to a thread-pool where children splash. This example by BrowserUK is a classic in my books: How to create thread pool of ithreads

1min addition: Sharing data between threads is possible but somewhat tedious, you want to keep it to a minimum (I don't like data duplicating), e.g. notifying of children pids. It is possible and easy to communicated via shared variables, integers, strings etc. but moving to shared deep data structures or objects is something you don't want because even if it is possible (I don't know) you can do without the overhead.

bw, bliako


In reply to Re: non-blocking backticks by bliako
in thread non-blocking backticks by chris212

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.