Gary Wright
2/28/2007 11:15:00 PM
On Feb 28, 2007, at 5:17 PM, Andreas S wrote:
> how do you check if your child process from fork still alive or
> not? In perl I can send kill(0, $cid), I think. But Process.kill(0,
> child_id) always returns 1.
>
> To be honest, I couldn't get the perl code to work either. It
> always returns 1 too.
>
> I can do `ps -p #{child_id}` but I wonder if Process.kill should
> work too.
Using Process.kill(0, pid) will return 1 as long as the process
exists. In
your situation, I'm guessing that the child process has terminated
but continues to exist as a zombie process. You have to call
Process.wait
to reap the child process in order for the child process to disappear
entirely.
pid = fork { sleep(10) }
puts Process.kill(0, pid) # 1
sleep 15
puts Process.kill(0, pid) # 1, process is a zombie at this point
Process.wait
puts Process.kill(0, pid) # exception, process doesn't exist
Gary Wright