Um, fork is what makes the children run in parallel. If
that isn't happening here, then your children probably aren't
doing much (since you aren't using wait or waitpid,
which can be used to make the parent wait children).
Doing some trick to make the children to appear more like
they are running in parallel will just slow things down.
If you just want to see that they are running in parallel,
then insert a sleep 5 in your child code.
-
tye
(but my friends call me "Tye")
| [reply] [d/l] |
One possible solution is to use something like Proc::Simple to handle all your forks as nice simple objects.
In your parent body, install a sig handler that traps, say SIGUSR1.
On a child death, the child 'kills' the parent with SIGUSR1, making it wake up from a lengthy sleep, or other work, and take care of the signal in whatever way you want.
I'd use SIGUSR1, as I may be doing other things that invoke pipes, and that keeps invoking the SIGCHLD handler, if I install that. Which gets messy.
At least with SIGUSR1, you can be pretty sure it's what you want sending the signal.
In Proc::Simple, you simply iterate over an array of process objects to see which ones have died and how.
Hope this helps a little,
Malk | [reply] |