From: bob@... (Bob Proulx) Date: 2004-10-10T13:00:55+09:00 Subject: Re: How to exit properly with a signal? gabriele renzi wrote: > Bob Proulx ha scritto: > > ruby -e 'sleep 10' ; echo $? > > -e:1:in `sleep': Interrupt from -e:1 > > 1 > > I guess you want: > trap("INT") { puts "interrupted" } Thank you for your reply. Unfortunately that does not work either. Run, then interrupt: ruby -e 'trap("INT") { } ; sleep 10' ; echo $? 0 The return code is now zero indicating a successful program completion. Of course I can exit with an error in the handler such as in the following example. ruby -e 'trap("INT") { exit 1 } ; sleep 10' ; echo $? 1 But again, this does not return the proper wait(2) status to the caller. The caller can't tell that the child process was terminated with a signal. In perl one does the following: $SIG{$sig} = 'DEFAULT'; kill($sig,$$); In C one does the following: act.sa_flags = 0; act.sa_handler = SIG_DFL; sigaction(sig,&act,0); raise(sig); I tried doing in ruby what I would do in perl. Basically the following. trap sig, "DEFAULT" Process.kill sig, $$ But no joy. Again my efforts were not able to produce the required results. ruby ./signals.rb ; echo $? starting program signal INT received, cleaning up ./signals.rb:5:in `sighandler': Interrupt from ./signals.rb:7 from ./signals.rb:7:in `call' from ./signals.rb:9:in `sleep' from ./signals.rb:9 1 How can I exit with the same wait(2) status as if the program was terminated on a signal? Hopefully someone will know the solution to this problem. Thanks Bob