in reply to Launching multiple commands in parallel

Use wait instead of waitpid. Wait returns when any child exits. Waitpid waits for a particular child.

Also see Running commands in parallel.


<cite>Just a tongue-tied, twisted, earth-bound misfit. -- Pink Floyd</cite>

Replies are listed 'Best First'.
Re: Re: Launching multiple commands in parallel
by steves (Curate) on Mar 06, 2002 at 16:39 UTC

    But wait doesn't support flags and will therefore pend until a child exits. So if you want to do something in the meantime, forget it -- you have to wait until at least one of your children is done. The way we used to do this in C was to keep track of our children's PIDs, then waitpid across the set without pending to reap any that were done. We'd work that into whatever processing we wanted to do while the children were running.

    I haven't done the same thing in Perl though so there may be a better way. Threads are another excellent model for doing this sort of thing but I haven't used them in Perl.

      I believe you can do waitpid(-1, &WNOHANG) to wait for all child processes. On some platforms.

      dave hj~

Re: Re: Launching multiple commands in parallel
by Capt_Howdey (Initiate) on Mar 07, 2002 at 14:36 UTC
    OK. I tried the run_parallel which seemed to work great for commands that return once launched. But it didn't seem to work for commands that can take up to 5 minutes to return the prompt (if run outside of perl). Yes, I have tried to put them in the background (&) but it did not make a difference.....
      Actually if i submit these commands in the background (&), STDERR is not sent back to the parent when they fail.....