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
That looks like a bug in the signal handling which was fixed in 1.9, to work around your problem, define the signal trap after the system call:
Not ideal, but it works.