On Oct 10, 2007, at 1:11 AM, Daniel DeLorme wrote:

> What are the possibilities in ruby for passing information from one  
> process to another? Specifically, I'm thinking of messaging between  
> a parent process and its forked child.
>
> Right now I can think of some messaging primitives:
> - TCPServer/TCPSocket
> - UNIXServer/UNIXSocket (unstable?)
> - IO.pipe (doesn't need port#)
> - Process.kill (impossible to send data)
>
> And some messaging libraries:
> - DRb (standard)
> - eventmachine (efficient?)
>
> ...what else? And, if anyone has the experience, what are the  
> advantages/disadvantages of each in terms of speed, reliability,  
> system resources?
>
> Thanks,
> Daniel

this is, by far, the easiest approach - it addresses exactly your  
problem by sticking a drb server in a forked child.  the child has  
arrangements made such that it can *never* outlive it's parent:

cfp:~ > cat a.rb
require 'slave' ### gem install slave

class Child
   def pid
     Process.pid
   end
   def foobar
     42
   end
end

slave = Slave.new{ Child.new }
child = slave.object

p Process.pid
p child.pid
p child.foobar


cfp:~ > ruby a.rb
20309
20310
42


also, if your arch changes it short work to rework such that the drb  
objects are not in a child process but, rather, are distributed  
across machines.

this code is used *heavily* in many of our production systems.

kind regards.

* http://codeforpeople.com/lib/ruby/slave/slave-1.2.1/README


a @ http://codeforpeople.com/
--
we can deny everything, except that we have the possibility of being  
better. simply reflect on that.
h.h. the 14th dalai lama