Skip to content

Instantly share code, notes, and snippets.

@evanphx
Created January 26, 2015 23:47
Show Gist options
  • Save evanphx/9caedb7dd11f8d5d89a1 to your computer and use it in GitHub Desktop.
Save evanphx/9caedb7dd11f8d5d89a1 to your computer and use it in GitHub Desktop.
on_fork advise
irb(main):003:0> require 'socket'
=> true
irb(main):004:0> s = TCPServer.new 9999
=> #<TCPServer:fd 10>
irb(main):005:0> Thread.new { s.accept }
=> #<Thread:0x007fedf33f0e88 run>
irb(main):006:0> c = TCPSocket.new "0.0.0.0", 9999
=> #<TCPSocket:fd 11>
irb(main):007:0> Process.fork { p $$ }
on_fork: Detected open IO at fork: #<TCPServer:0x007fedf33e8f08>
on_fork: Detected open socket to 127.0.0.1:62284 at fork
on_fork: Detected open socket to 127.0.0.1:9999 at fork
=> 38218
irb(main):008:0> 38218
irb(main):009:0* exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment