One method is to keep pipes open to the children - if you have a pipe which the parent reads and the child writes, you can send your dots (valid progess indicators :) down the pipe. You then remove file locking problems (which you have with writing dots to a file). You end up with a parent with a whole bunch of pipes - just do a select() on these, and you'll get woken up whenever there's anything to read from them.

Pipes were pretty much invented for this - they survive fork (i.e., both child and parent can still see it!). Pipes rock :) Programming Perl has some other good examples of IPC - shared memory, sockets, etc., but all that's a bit overboard for what you want. The usual pipe way is:

pipe(READHANDLE, WRITEHANDLE); my $result = fork(); if ($result>0) { # child process, we write to the pipe } else { # parent process, or error - might want to check before # we try to read from pipe :)) }

If you want more than one child, just keep the handles in an array so you don't lose them, and do a select() in the parent when all the children are active.

Oh, and beware of buffering - probably best to turn that off when debugging :)


In reply to Re: Using signals in Perl by kal
in thread Using signals in Perl by leons

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.