in reply to Trouble getting started with fork

Unless this is for the learning experience, you might want to look into Parallel::ForkManager...

Replies are listed 'Best First'.
Re^2: Trouble getting started with fork
by ikegami (Patriarch) on Mar 03, 2010 at 21:12 UTC
    The code behind P::FM is pretty straightforward and well organized. Looking at P:FM would be a good idea even if this is a learning experience.
Re^2: Trouble getting started with fork
by sierpinski (Chaplain) on Mar 04, 2010 at 17:17 UTC
    Yes, Parallel::ForkManager has a 'maxprocs' setting which explicitly tells the script how many processes to spawn at any given time. As soon as one finishes, a new one is spawned until the script is completely finished.

    An alternative would be to have each child process return a value (1, for example) so you can use that in the parent process to keep a counter. When one starts, increment. When one finishes, decrement, and only spawn a new process if counter < 5.

    /\ Sierpinski