That's how processes work, with no special action required:
$ cat parent_and_child.rb
fork do
5.times do
puts "Child still running..."
sleep 1
end
puts "Child exiting."
end
2.times do
puts "Parent still running..."
sleep 1
end
puts "Parent exiting."
$ ruby parent_and_child.rb
Parent still running...
Child still running...
Parent still running...
Child still running...
Parent exiting.
Child still running...
$ Child still running...
Child still running...
Child exiting.
James Edward Gray II
···
On Dec 18, 2010, at 12:10 PM, Tasos Laskos wrote:
I'm having a bit of a problem...
Is there a way to completely detach child processes?
What I mean is, if I Kernel.fork() a piece of code and then the parent
gets killed I want the child to continue running.
And that's why I chose to work with Processes and not Threads.
I recalled that that's their default behaviour but for some reason when
the parent XMLRPC server dies his children die too.
(The children are also XMLRPC servers serving a different purpose.)
That's what's bugging me...
*Lightbulb*
The children are listening on stdin too so they probably catch the
Ctrl+C interrupt and die as well.
But I don't want that either...is there a way to separate them
completely or will I have to settle?