Forking with block leaves zombie procs

I’m still in the process of reducing this to a simple test case, but
I thought I’d post and see if anybody had suggestions. I am starting
a bunch of test cases, and then forking to wait on the success or
failure of the tests. Currently, it looks something like:

test_list.each {|test|
start_test(test, machine)
fork {
sleep 20 while !test_finished(test, machine)
get_test_logfiles(test, machine)
exit(0)
}
}

However, every time I run this code, I get a zombie process sitting
around, waiting for init to reap it. If I’m running a bunch of tests,
this can get really annoying, and clutters up the process table
something fierce. Any ideas on how to prevent this happening? I
tried nesting fork blocks, but that didn’t work. This isn’t a
ruby-specific issue, I don’t think (unless it’s something to do with
forking with blocks instead of using fork()), but I’ve a mental block
on where to proceed.

-=Eric

···


Come to think of it, there are already a million monkeys on a million
typewriters, and Usenet is NOTHING like Shakespeare.
– Blair Houghton.

Zombies need you to Process.wait for them to decompose.

···

On Wed, 18 Dec 2002, Eric Schwartz wrote:

However, every time I run this code, I get a zombie process sitting
around, waiting for init to reap it. If I’m running a bunch of tests,


Greg Millam
walker at deafcode.com

Hi,

···

At Wed, 18 Dec 2002 08:07:45 +0900, Eric Schwartz wrote:

However, every time I run this code, I get a zombie process sitting
around, waiting for init to reap it. If I’m running a bunch of tests,
this can get really annoying, and clutters up the process table
something fierce. Any ideas on how to prevent this happening? I
tried nesting fork blocks, but that didn’t work. This isn’t a
ruby-specific issue, I don’t think (unless it’s something to do with
forking with blocks instead of using fork()), but I’ve a mental block
on where to proceed.

If you don’t need the exit status, prepend this line.

trap(“CHLD”) {Process.wait(-1, Process:WNOHANG)}


Nobu Nakada

nobu.nokada@softhome.net writes:

If you don’t need the exit status, prepend this line.

trap(“CHLD”) {Process.wait(-1, Process:WNOHANG)}

But, AIUI, that wouldn’t kick in if the parent process has exited before
child process dies, which is the case here. I thought init was supposed
to reap them in that case, but it doesn’t appear to be doing so, since
I can generally go to the machine at any point and see tons of zombies
lying around there.

-=Eric

···


Come to think of it, there are already a million monkeys on a million
typewriters, and Usenet is NOTHING like Shakespeare.
– Blair Houghton.

Hi,

···

At Thu, 19 Dec 2002 15:54:57 +0900, Eric Schwartz wrote:

If you don’t need the exit status, prepend this line.

trap(“CHLD”) {Process.wait(-1, Process:WNOHANG)}

But, AIUI, that wouldn’t kick in if the parent process has exited before
child process dies, which is the case here. I thought init was supposed
to reap them in that case, but it doesn’t appear to be doing so, since
I can generally go to the machine at any point and see tons of zombies
lying around there.

If there were zombies, the parent process IS alive. Otherwise
your system’s init is broken or suspended.


Nobu Nakada