Don't ask to ask, just ask | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
I'm not sure what reap_children is supposed to do. What it does is reap any dead children. Your args to waitpid say "Check to see if any processes are dead, but don't hang this process waiting." You also don't seem to be doing anything with $kid since if more than one process dies, you ignore the pid of the first one. Follow maverick's advice if you care when they are all dead. If you are just trying to avoid zombies, do $SIG{CHLD} = sub {wait}; It really depends on what you want to do.
Now, why does your process appear to wait for some children to die? Well, one possibility is that you have exceeded the maximum number of children your OS allows. That is, if you have a lot of files to process, you may have forked as many children as you are allowed to fork. To figure that out you can keep track of the number of live children and see if that number gets big. The limit on my system is 511. BTW you can avoid the magic numbers in waitpid if you use POSIX "sys_wait_h";. HTH, --traveler Update: I'd never heard about the 2% chance of corruption. I've always followed the Camel's advice about using the signal handler, I guess I've been lucky. Maybe one choice is to do a periodic wait for children using code similar to reap_children. You might also try setting $SIG{CHLD} to SIG_IGN. In reply to Re: fork()ing a large process
by traveler
|
|