in reply to Re: fork()ing a large process
in thread fork()ing a large process

Note that $SIG{CHLD}= sub {wait}; has another problem. If two children exit at nearly the same time, the two SIGCHLD signals can arrive close enough together that the signal handler only gets called once. Each time this happens, you'd get one more zombie hanging around.

Back to the original problem, I'd add some debug print statements so that you can figure out exactly where the process is hanging.

Also, $SIG{CHLD}= 'IGNORE'; only works on some operating systems (SysV-based ones, as I recall).

        - tye (but my friends call me "Tye")

Replies are listed 'Best First'.
Re: (tye)Re2: fork()ing a large process
by traveler (Parson) on Nov 29, 2001 at 23:40 UTC
    You are correct that the wait should be in a loop such as the reap_children function has. I was clearly not thinking clearly... Also, on SYS V systems IIRC CHLD or CLD signals are regenerated if you do not do wait on the clild so the race condidion you mention may not hold true there and wait by itself should work. I suppose I've been using SYS V-based systems too much to think of some of these issues. My bad.

    tye is correct. To be portable you'll need to find another solution. I have used non-blocking waits in a timer loop to clean up children and that may work here. Of course, if you don't care about portability, use what works on your system and document that it isn't portable.