From: Robert Klemme Date: 2006-11-05T19:55:15+09:00 Subject: Re: trap and multiple occurences On 05.11.2006 02:59, Gabriele Marrone wrote: > A very good practice is writing signal handlers that just set a global > variable with the signal(s) received, and then check that variable and > actually do something from within the application main loop. > There are many good reasons, some are here: > http://www-128.ibm.com/developerworks/linux/library/l-reent.html > (In fact I just googled for a link that explains what I'm thinking, I'm > lazy and sleepy so I didn't read throughly that page and I hope it > really says what I mean :P) The way I'd probably do it is to set up a Queue and have a reader thread that will process signals placed into the queue. Something along the lines like this require 'thread' SIG_HANDLER = Queue.new Thread.new do while ( sig = SIG_HANDLER.deq ) print "SIGNAL: ", sig.inspect, "\n" end end Signal.list.each do |name, sig| Signal.trap sig do |s| SIG_HANDLER.enq s end end 20.times do puts "." sleep 1 end Kind regards robert