diff options
| author | mo khan <mo@mokhan.ca> | 2013-08-28 07:20:13 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2013-08-28 07:20:13 -0600 |
| commit | db1191ec0e7305d684383f8974e2fa437f77ad5a (patch) | |
| tree | 5e27b197dff849d22d8e1f50eb75aa499b16bd06 /code/snippets/prefork.rb | |
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 |
