Take the 2-minute tour ×

For some signals, like SIGINT, I can easily enough set up a trap to handle the signal and continue execution as I see fit. I'd like to add typical behavior for ^q and ^s to a ruby command-line application that I'm fiddling with. Is there a way to do this - particularly, one that is portable so I can use it in Windows, iOS, Linux and Solaris?


It turns out that the signals are never delivered to the process. In fact, running strace on the process and on its parent process, a bash instance, showed that neither the process nor the parent were getting any indication of what was going on. They're simply being suspended.

I may try to have a SIGALARM handler that fires once per second, checks to see if much more than a second has passed since the last alarm, and makes appropriate calls if it concludes that the process has been suspended. There would be false positives on a heavily-loaded system.

share|improve this question

1 Answer 1

In irb enter Signal.list. It will list all the signals you should be able to trap.

Trap a signal in ruby:

Signal.trap("STOP") do
  # handle the signal

In the terminal enter $ stty -a. It should list signals and their associated key combo (if they have one).

I believe ^s is usually stop and ^q is start.

Although according to this answer, those key combos do not actually send a signal to the running process, but instead to the terminal driver. In that case, kill -STOP <process> can send that signal to your process.

share|improve this answer
^Q is usually SIGKILL as I remember. –  hauleth Sep 11 '12 at 21:36
@Hauleth I think it is system dependent. ^U is SIGKILL on my system. –  ajjahn Sep 11 '12 at 21:59
While both cygwin/windows and linux recognize the Signal.trap("STOP") line, neither accepts start (though both show the start signal in stty -a). If I set a trap on STOP, neither will execute the signal handler (a simple puts) when ^S is hit. –  Sniggerfardimungus Sep 11 '12 at 23:01

Your Answer


