[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

How to check if child process is still alive?

Andreas S

2/28/2007 10:17:00 PM

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.

-andre

_________________________________________________________________
Win a Zune??make MSN® your homepage for your chance to win!
http://homepage.msn.com/zune?icid=...


2 Answers

Ara.T.Howard

2/28/2007 11:12:00 PM

0

Gary Wright

2/28/2007 11:15:00 PM

0


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