SPUG:Child Processes

ced at carios2.ca.boeing.com ced at carios2.ca.boeing.com
Tue Feb 18 11:35:05 CST 2003

> I have a script that releases a varying number of other scripts.

> I am trying to make the parent wait until all the children finish,
>  but other then the brute force method of looping thru watching the
> processes in the process list while looking for a key phrase I have
> not been able to make the parent wait for all the children to finish.

> In Korn shell you can put in a wait statement after releasing the
> children and all is well, but perl does not seem to have a simple
> equivilent.

How are you launching the other scripts..? If you were using
system or backtick execution, your program would automatically
wait until they're complete. So, I'll assume you background 

To avoid scanning the process table, one possibility is to fork 
the other scripts (assuming Unix) in order to harvest the process 
ID's and explicitly wait for their completion. The recommended
method is a non-blocking wait loop inside a SIGCHLD signal
handler. There's a good discussion of that in the 'Perl
Cookbook' in the 'Avoiding Zombie Processes'. Or check
'perdoc -q zombie'. The Cookbook notes some key wrinkles:
a backgrounded process can be stopped and send a SIGCHLD
when continued. Also, system or backtickk execution elsewhere
in your program may reap one of your processes from under
you. Or, conversely, your handler may reap other system or 
 backticked calls and their result codes will be unexpected.

Charles DeRykus

More information about the spug-list mailing list