From: "ara.t.howard" Date: 2007-12-28T23:58:42+09:00 Subject: portable signals cfp:~ > cat a.rb # # on windows signals don't work. least wise you cannot send, for instance, # SIGABRT to another process. rather, you can only signal yourself! to get # around this limitation a tiny drb service, fronting the Process object # itself, can be setup to allow one process to signal another by making a drb # call that actually causes the other process to signal *itself*. you've # really got to love ruby at times like these. # require 'drb' mode = ARGV.shift || 'servant' uri = ARGV.shift signal = 'ABRT' start_server = lambda do trap(signal){ puts "#{ Process.pid } got #{ signal }..." } DRb.start_service 'druby://localhost:0', Process uri = DRb.uri end start_client = lambda do DRb.start_service 'druby://localhost:0' process = DRbObject.new nil, uri end case mode when /server/i puts "server.pid => #{ Process.pid }." uri = start_server.call puts DRb.uri loop do puts "not blocking..." sleep 1 end when /client/i puts "client.pid => #{ Process.pid }." process = start_client.call process.kill signal, process.pid when /servant/i puts "server.pid => #{ Process.pid }." uri = start_server.call Thread.new do loop do puts "not blocking..." sleep 1 end end program = __FILE__ client_program = "ruby #{ program } client #{ uri }" 4.times do system client_program sleep 1 end end cfp:~ > ruby a.rb server.pid => 1593. not blocking... client.pid => 1594. 1593 got ABRT... not blocking... client.pid => 1595. 1593 got ABRT... not blocking... client.pid => 1596. 1593 got ABRT... not blocking... client.pid => 1597. 1593 got ABRT... not blocking... a @ http://codeforpeople.com/ -- it is not enough to be compassionate. you must act. h.h. the 14th dalai lama