in reply to fork and mailing lists

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.

Replies are listed 'Best First'.
Re: Re: fork and mailing lists
by Anonymous Monk on Nov 03, 2001 at 21:10 UTC
    Thanks joealba,
    But I'm not good coder, could you explain please.
    Where does your code go in mine?
    Could you comment your variables?

    Thanks again,
    Adrien