[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Re: How to check if child process is still alive?

Andreas S

3/1/2007 12:36:00 AM


>You have to call Process.wait to reap the child process in order for the
>child process to disappear entirely.
>
>Gary Wright
>

I don't want to use Process.wait because it will block. I have a queue that
I want to refill with the next job in line when a slot is available. I'm not
gaining much from forking jobs like this but my main purpose is to emulate
LSF queue on local machine, in case its down or something. By doing so, the
rest of the code still sees a queue.

I tried Ara's suggestion, but it doesn't seem to throw exception.

Thanks for such prompt response and I love how Ara, even for merely showing
example, gave
alias alive? alive
:)

-andre

def alive pid
pid = Integer("#{ pid }")
begin
Process::kill 0, pid
true
rescue Errno::ESRCH
false
end
end

c = fork do
sleep 5
print "Child exits"
exit
end

while alive c
print '.'; STDOUT.flush
sleep 1
end

>>ruby test.rb
......Child exits.........

_________________________________________________________________
Find what you need at prices you?ll love. Compare products and save at MSN®
Shopping.
http://shopping.msn.com/default/shp/?ptnrid=37,ptnrdata=24102&tcode=T001...


1 Answer

Daniel DeLorme

3/1/2007 1:17:00 AM

0

Andreas S wrote:
>
>> You have to call Process.wait to reap the child process in order for
>> the child process to disappear entirely.
>
> I don't want to use Process.wait because it will block.

Then you should use Process.detach(child_pid)

Daniel