Clear questions and runnable code get the best and fastest answer |
|
PerlMonks |
Re: Load-sharing parentby FloydATC (Deacon) |
on Dec 08, 2014 at 17:43 UTC ( [id://1109613]=note: print w/replies, xml ) | Need Help?? |
The simplest way is to use a module as suggested, but if you want to invent your own wheel it's not very difficult. Simply have your master process keep the return value (pid) every time you fork(), use it as a hash key and regularly use waitpid() to check for finished child processes. The hash can be used for keeping track of whatever each child is tasked with. Cleaning up after a child could include reading back results before deleting the hash key. If you don't like the waitpid() looping you could also rely on a signal handler, but in practice I find this is a little more tricky to get 100% right.
-- FloydATC
Time flies when you don't know what you're doing
In Section
Seekers of Perl Wisdom
|
|