From: Joseph McDonald Date: 2001-06-16T10:03:27+09:00 Subject: [ruby-talk:16523] Re: forking server JM> Here's a stab at a forking server. The problem is that it exits JM> after the first connection and I don't understand why... JM> Can anyone enlighten me? Ah, I see the problem... I thought that the "trap" was working in the child, but really it's in the parent. Just removed that "exit" and things seem to be working fine (also added a new_sock.shutdown): require 'socket' trap("CLD") { pid = Process.wait puts "Child pid #{pid}: terminated" } s = TCPServer.new("0.0.0.0",8888) while(new_sock = s.accept) pid = fork puts "pid: #{pid.inspect}" if(pid == nil) # Child process # do stuff here... line = new_sock.gets line.chop! puts line new_sock.puts "you said: #{line}" new_sock.shutdown exit end end puts "exiting..." s.close regards, -joe