Skip to content

Instantly share code, notes, and snippets.

@seki seki/forktest.rb
Last active Oct 14, 2019

Embed
What would you like to do?
close on fork
require 'drb'
def test_fd
sleeper = DRbObject.new_with_uri('druby://localhost:50097')
ary = 20.times.collect {
Thread.new { sleeper.sleep(5) }
}
ary.each {|th| th.join}
system("lsof -p #{$$} | wc -l")
fork {
system("lsof -p #{$$} | wc -l")
GC.start # close on fork and GC (new one)
system("lsof -p #{$$} | wc -l")
sleeper.sleep(0.1) # close on dRuby call. (PR Fix some DRb issues #2552)
system("lsof -p #{$$} | wc -l")
}
end
test_fd
gets
test_fd
gets
require 'drb'
class Sleeper
def sleep(n)
puts "sleeping: #{n}"
Kernel.sleep(n)
end
end
DRb.start_service('druby://localhost:50097', Sleeper.new)
gets
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.