> I can't use system because , a nested command in my program is not
> allowed, so i try the fork.
> I try with waitpid($pid, XXXX) but i didn't know how to tell 
> the waitpid
> that waits for the child and don't continue 
> 
> waitpid($pid,&WNOHANG) ====> continues execution without 
> waiting for the
> child, doesn't it?
> waitpid($pid, !WNOHANG) ===> will wait for the child? 
> what is the meaning of the '&'?
> Is there another flag?

just call waitpid($pid) and the parent will block until the child pid
returns.  If you want to do non-blocking you need the flag but it sounds
like that's the problem you're trying to avoid.  

There are lots of other issues you might run into here, like what happens if
your child process hangs?  Are you reaping zombie processes?  You might want
to think about these things as well.  To handle them you will probably need
to setup some signal handlers.  Theses might be as simple as
$SIG{CHLD}='IGNORE' and $SIG{ALRM} = sub {my gracefull exit routine;}  but
you should probably do something.  If you have the alarm handler set then
you can call alarm($seconds) before going into your dangerous code section.

Do a perldoc on alarm and/or check out the perl cook book's section on
running multiple processes.

Hope this helps,
Peter C.

Reply via email to