spaz and TheoPetersen were right. ForkManager is good stuff! Here's the sample code:
use Parallel::ForkManager; # Max number or processes you want to fork at one time. # Set this to something reasonable so you don't thrash your box. my $MAX_PROCESSES = 5; # J. Random list of numbers. my @things = (1..10); my $pm = new Parallel::ForkManager($MAX_PROCESSES); # Start looping through my list of numbers foreach my $thing (@things) { # This is more of a loud comment than anything else, # just telling you that the parent is about to # fork a child. print "Forking off $thing...\n"; # Kick off the child process. # If this is the parent process, # we'll move on to the next step in this loop $pm->start and next; # This is your child process. # There are many like it, but this one is yours. :) # Do your forked goodness here print "$thing\n"; $pm->finish; # The child has finished. Tell him to clean up his room. } $pm->wait_all_children;
Just keep your $MAX_PROCESSES at something reasonable for your system, and all should be fine.

Updated: Added comments. In this code, I have a list of numbers. I loop through that list of numbers and fork off child procs which simply print that number.

I'm sorry to say this, but if you can't extend this code to do what you want, you really shouldn't be writing this code. You must always practice safe forking.

In reply to Re: fork and mailing lists by joealba
in thread fork and mailing lists 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.