in reply to Should I call waitpid when using Parallel::ForkManager to fork in an infinite loop?

That's not a problem. start reaps children as well. Consider the following example:

my $max_children = 5; my $pm = Parallel::ForkManager->new($max_children); for my $i (0..9) { $pm->start and next; #... $pm->finish; } $pm->wait_all_children;

With your infinite loop, it's no different. You'll be reaping child every time you create one (once you've created $max_children children).

It's a bug to use waitpid in a run_on_finish handler since the process has already been reaped by then.

  • Comment on Re: Should I call waitpid when using Parallel::ForkManager to fork in an infinite loop?
  • Select or Download Code

Replies are listed 'Best First'.
Re^2: Should I call waitpid when using Parallel::ForkManager to fork in an infinite loop?
by BioLion (Curate) on Aug 16, 2009 at 12:04 UTC

    Is that true? I thought that $pm->finish did the reap, and allowed the manager to start another process (assuming that $max_procs processes have been started already)?

    So the OPs code would maintain $max_procs children at all time (because of the while (1) ), and as you said, no explicit cleanup or reaping need be added, because of the wonderfulness of Parallel::ForkManager!

    Just a something something...

      I thought that $pm->finish did the reap

      finish is only executed in the child. It can't do any reaping.