# Trapped signals killing my subprocesses

**URL:** <https://www.ruby-forum.com/t/trapped-signals-killing-my-subprocesses/114050>\
**Category:** Ruby\
**Created:** [September 7, 2007, 11:11am UTC](https://www.ruby-forum.com/t/trapped-signals-killing-my-subprocesses/114050 "2007-09-07T11:11:20Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![elliterate](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/9de053/32.png) [@elliterate](https://www.ruby-forum.com/u/elliterate)\
**Post date:** [September 7, 2007, 11:11am UTC](https://www.ruby-forum.com/t/trapped-signals-killing-my-subprocesses/114050/1 "2007-09-07T11:11:20Z")

</div>

Hey list,

I have a problem with trapping signals in the main thread whilst a  
subprocess is running in another thread. The signal is properly trapped,  
however it doesn’t seem to stop the signal from being sent to the  
subprocess. Is this an inherent side effect of green thread  
implementations?  
Can anyone suggest a workaround?

The code here demonstrates my problem. Run it, and hit ^C. My  
expectation  
was not to see ‘killed :(’ until the 10 seconds are up.

#!/usr/bin/ruby

class Sleeper \< Thread

def initialize  
super do  
IO.popen(‘sleep 10’) {|f| puts f.gets }  
puts “killed :(”  
end  
end  
end

Signal.trap(‘INT’) { puts “Signal trapped.” }

a = Sleeper.new  
a.join

Cheers  
Ian

---

<div class="post-metadata">

**Author:** ![elliterate](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/9de053/32.png) [@elliterate](https://www.ruby-forum.com/u/elliterate)\
**Post date:** [September 7, 2007, 8:20pm UTC](https://www.ruby-forum.com/t/trapped-signals-killing-my-subprocesses/114050/2 "2007-09-07T20:20:26Z")

</div>

Yeah that seems like unexpected behavior. I guess ctrl-c is being by  
default passed to the subprocess. In my experience ctrl-c is either  
passed to any currently ‘being run’ subprocess, OR to Ruby (like begin  
… rescue Interrupt…end) but not to both, which happens here. Odd, I  
agree.

-Roger
