go ahead... be a heretic | |
PerlMonks |
Re: Keeping children alive persistiently, intelligentlyby kyle (Abbot) |
on Feb 08, 2008 at 20:13 UTC ( [id://667057]=note: print w/replies, xml ) | Need Help?? |
This sounds like a job for POE, but I don't know enough about that module to say for sure. If I were writing this, I'd be strongly tempted to make each child into an object. You could stash within it $params and all the other state that you're trying to hold and modularize all the behavior you want them to have. Each child object in the parent would know the PID of the child process, the parameters it started with, how many times it has died, etc.
Something like:
This is just a sketch, but hopefully you get the idea. Having written all this, I'm now guessing that someone will come along with a much better CPAN module I've never heard of. Update: Upon further consideration, I'm not sure this is such a hot idea. Each child is a copy of the whole, so each has a copy of all the child objects. As soon as one of them dies, it's going to shoot all the other ones in their destructors. Oops. You could still have them all manage themselves except for the DESTROY methods. In that case, the parent would have to kill them all manually in an END {} block. Update 2: Another thought. You could write DESTROY this way:
Then you have spawn note the parent PID before it forks
In Section
Seekers of Perl Wisdom
|
|