SIGINT not being captured immediately after using system() command

When I ran the ruby code below, pressing ctrl + c would immediately stop
the program

trap(“INT”) { exit }
while line = gets; puts line; end

However, when I use system() command before the gets, pressing ctrl + c
would not take any effect unless I hit “Enter”. It seems like it has to
do with system() forking a child process and somehow the parent could no
longer detect SIGINT. How would you change the code so that ctrl + c
would take immediate effect for the code below

trap(“INT”) { exit }

if system(“which ruby > /dev/null”)
puts “ruby is installed”
end

while line = gets; puts line; end

I also tried to debug the problem by using dtruss (i’m on a mac) while
the ruby program is running and tried to see what the differences are
between the two. Problem is, I don’t fully understand the output.
Comparing them though, it seems like what enabled the 1st program to
exit immediately on “ctrl + c” during gets is that the
__pthread_canceled system call was executed.

If you guys have more insights into this, let me know:

case 1 (SIGINT with no system before gets) dtruss output:
http://pastie.org/3305367
case 2 (SIGINT with system before gets) dtruss output:
http://pastie.org/3305276

Btw, the behavior I described only happens on ruby-1.8.7-p357. When I
switched to ruby-1.9.2-p290, ctrl + c immediately exits the program for
both cases.