As usual, I just realised that I've misunderstood the problem. Given the way
Process.kill() works, I should still be able to tell whether the process is
running, because once it's gone, Process.kill() should return zero.
So, I did a little more investigation and discovered that once the process had
exited, it was still hanging around as a defunct process.
This surprises me somewhat. What I'm doing (in essence) is ...
if pid = Kernel.fork.nil?
exec "/bin/sleep", 30
else
loop do
puts (Process.kill(0, pid) == 1) ? "alive" : "dead"
sleep 10
end
end
I would have thought that once the /bin/sleep had completed, the child process
would disappear, but, as I say, it seems to become a defunct process.
Obviously, I don't want that.
Any ideas?