Created
December 27, 2012 00:51
-
-
Save anonymous/4384447 to your computer and use it in GitHub Desktop.
sample code from "Working With Unix Processes" $ telnet localhost 3000
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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