in reply to Re: Re: Perl IPC: Checking Exit Status of Child Process
in thread Perl IPC: Checking Exit Status of Child Process

Here's an example of one parent forking multiple children.

The Perl Cookbook has great examples about this topic.

You'd really want to make sure you're looping around the fork() and keeping track of the number of living children you have at the moment. Other than that and IPC, it's mostly just everyday programming.

Christopher E. Stith
use coffee;
  • Comment on Re: Re: Re: Perl IPC: Checking Exit Status of Child Process

Replies are listed 'Best First'.
Re: Re: Re: Re: Perl IPC: Checking Exit Status of Child Process
by bayruds (Acolyte) on May 19, 2003 at 17:16 UTC

    Hi
    Thank you very much for replying back. I had a question
    regarding multiple forks in a loop:
    1. How do I ensure that all child processes are running conurrently
    2. Also, How can I execute different subroutines for each child
    Looking forward to hear from you.
    Thanks
      1) That requires IPC of some sort.

      2) TMTOWTDI.

      2a) You could increment a status variable meant specifically for this purpose before the fork() in the parent, and each child would then get their private version of that variable after the fork() at the value that was current during the fork(). You could then run a different sub or exec() a different file based on the value of that variable.

      2b) This is more complex than the above. You could have each child communicate back to the parent to ask.

      2c) You could keep a file/database entry for each task that has been started (like a pid file) and start whichever one is next.

      My vote for #2 is 2a.

      Christopher E. Stith
      use coffee;