A solution using Proc::Queue:

One process is created to perform the data load while several (4) processes handle the data conversion. The conversors tell to the loader when they finish through a pipe.

Proc::Queue is used to ensure that only 4 conversors + the loader run at the same time

# untested: use Proc::Queue size => 4, qw(run_back); my $lpid = open my $loader, '|-'; defined $lpid or die "unable to fork: $!"; if ($lpid) { select $loader; $| = 1; select STDOUT; for (@ARGV) { run_back { if (system("convert.sh $payload") == 0) { print $loader "$payload\n"; } else { warn "Couldn't launch: $!/$?"; } } or warn "unable to fork: $!/$?"; } } else { while (<>) { system "load_db.sh $_") == 0 or warn "Couldn't launch: $!/$?"; } } 1 while wait != -1;

In reply to Re: Converting a parallel-serial shell script by salva
in thread Converting a parallel-serial shell script by Corion

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.