Have you ever met a program that no matter how hard you hit
Ctrl-C, it just wouldn’t stop?
I was a little annoyed by such behavior of the bc (basic calculator) program on Mac (or FreeBSD):
$ bc -q (interrupt) use quit to exit.
To achieve that in Ruby is simple:
loop do input = gets.chomp exit if input == 'quit' # calculate(input) trap(:INT) do puts '(interrupt) use quit to exit.' end end
Some processes even wouldn’t stop when we try to kill it:
$ kill <pid>
In such cases, the
SIGTERM signal sent by
kill is trapped.
We can force them to stop by sending the the
SIGKILL signal, since it cannot be caught:
$ kill -s KILL <pid>