There's more than one way to do things | |
PerlMonks |
Re: Iteration problem on a tied arrayby fokat (Deacon) |
on Oct 18, 2001 at 00:31 UTC ( [id://119556]=note: print w/replies, xml ) | Need Help?? |
In your code, if the ps command returns the processes in different order, you might duplicate or miss childs. Do a sort { $a <=> $b } ... to insure that the array is in a consistent order after different calls. Note that if a child terminates between calls to FETCH, you're bound to miss / loss childs while traversing the array. Perhaps a better way to approach this problem would be catching SIG_CHLD and providing a custom fork() method that kept track of how many children and when they die. This would avoid doing a ps for each element of the array, each time you iterate over it. Finally, if you're on a multiuser system, please place a sleep(1) or something like that in the infinite loop of the child. You're burning CPU time for every children you spawn in your test. Good luck and hope this helps...
In Section
Seekers of Perl Wisdom
|
|