Skip to content

Instantly share code, notes, and snippets.

Created December 27, 2012 00:51
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/4384447 to your computer and use it in GitHub Desktop.
Save anonymous/4384447 to your computer and use it in GitHub Desktop.
sample code from "Working With Unix Processes" $ telnet localhost 3000
require 'socket'
socket = TCPServer.open('0.0.0.0', 3000)
[:INT, :QUIT].each do |signal|
Signal.trap(signal) {
wpids.each { |wpid| Process.kill(signal.wpid) }
}
end
wpids = []
10.times {
wpids << fork do
loop {
connection = socket.accept
connection.puts "Hello Readers!"
connection.close
}
end
}
Process.waitall
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment