From: ara.t.howard@... Date: 2006-06-05T00:14:11+09:00 Subject: Re: Please kill the children as you're leaving On Sun, 4 Jun 2006, Francis Cianfrocca wrote: > How does your parent process die unexpectedly? If it catches signal 9, for > example, your atexit handlers won't run. You could try something dramatic > like open a socketpair between parent and child processes (don't forget to > turn off CLOEXEC for forking) and then have the child processes periodically > send a byte to the parent. If you lose the parent, then the write from the > child should catch SIGPIPE. Also possible is for the children to > periodically to check the status of the parent process (getppid). indeed. this is exactly what my slave library does - it sets up a heartbeat pipe between parent and child. this way, even if the parent dies via 'kill -9', which no code can handle, the child will die. eg. harp:~ > cat a.rb # http://codeforpeople.com/lib/ruby/slave/ require 'slave' class Child def initialize @pid = Process.pid Thread.new{loop{warn "child <#{ @pid }> @ <#{ Time.now }>"; sleep 1}} end end class Parent def initialize @pid = Process.pid @child = Slave.new(Child.new) sleep 3 Process.kill -9, @pid end end Parent.new harp:~ > ruby a.rb child <26196> @ child <26196> @ child <26196> @ Killed ps. the gem for slave is on rubyforge but, for some reason, a 'gem install slave' does not work. you can download the gem manually here: http://rubyforge.org/frs/?group_id=1024&release_id=5464 pss. this is setup exactly like all the other projects under codeforopeople - if anyone has any ideas on why slave installs fail please contact me offline. cheers. -a -- suffering increases your inner strength. also, the wishing for suffering makes the suffering disappear. - h.h. the 14th dali lama