diff options
Diffstat (limited to 'code/snippets/prefork.rb')
| -rw-r--r-- | code/snippets/prefork.rb | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/code/snippets/prefork.rb b/code/snippets/prefork.rb new file mode 100644 index 0000000..65b285f --- /dev/null +++ b/code/snippets/prefork.rb @@ -0,0 +1,29 @@ +require 'socket' + +# Open a socket. +socket = TCPServer.open('0.0.0.0', 8080) + +# Preload app code. +# require 'config/environment' + +# Forward any relevant signals to the child processes. +[:INT, :QUIT].each do |signal| + Signal.trap(signal) { + wpids.each { |wpid| Process.kill(signal, wpid) } + } +end + +# For keeping track of child process pids. +wpids = [] + +5.times { + wpids << fork do + loop { + connection = socket.accept + connection.puts 'Hello Readers!' + connection.close + } + end +} + +Process.waitall
\ No newline at end of file |
