It sounds like you want to use fork() to launch each of the four processes -- something like this (untested): update: Based on ikegami's more knowledgeable reply, the following is the sort of thing you'd do if you weren't using Windows; but if you replace the fork stuff with your original "system 1,...", I think the while loop using "wait" will still do what you want.
my %children; for my $n ( 1..4 ) { my $child = fork; if ( !defined $child) { die "fork failed on $n: $!" } elsif ( $child == 0 ) { # this is what the child does: exec 'some', 'process', $n; } $children{$child} = $n; } while ( keys %children ) { my $reaped_pid = wait; if ( exists( $children{$reaped_pid} )) { checkerror_function( $children{$reaped_pid} ); delete $children{$reaped_pid}; } else { # if you get here, better study "perldoc perlipc" } }
I would assume that the "checkerror" function needs to know which of the sub-processes has just finished, so that it knows which set of output to check. That's why I kept track of the loop counter when forking, and pass it to checkerror_function when reaping.

(update: fixed missing close-quote and added slight improvement to "die" message)


In reply to Re: question about running a system and a perl function background by graff
in thread question about running a system and a perl function background by Anonymous Monk

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.