Sending signals with the keyboard

When I was young and green with Linux, I was introduced to CTRL+C. Since then I have been happily destroying processes from the keyboard. For a long time I had little to know understanding as to what was really happening when I hit CTRL+C, I just knew that most of the time it worked, the process died and I could get on with my shell. But eventually I learned about Unix signals, how they worked, what they are and what invoked them. The much beloved CTRL+C for instance sends a signal 2 to the process, a signal 2 is then handled by the process. A process can recieve and ignore a CTRL+C if it has been programmed to, or if the process space has been “convoluted” then the CTRL+C might not work at all, or even make matters worse.

A good example of CTRL+C making life worse can be found with python threads, if an application has multiple cpu-bound threads running in the python interpreter then executing CTRL+C can cause the python GIL to go BANANAS and the python application starts hammering the system.

But this post is not about the Python GIL, it is about signals, so go ahead and open up the 7th chapter of the signal manpage with a good ol’ man 7 signal and scroll down until you start to see numbers. This is where all of those crazy Unix signals are defined, and as you will discover, signal 2 is a SIGINT signal. A few other noteworthy signals are signal 15, the default signal sent with the kill command, and signal 9, most likely the most common signal sent when altering the options to the kill command.

But there are more signals which can be sent with the keyboard, in particular CTRL+Z, and my new favorite a CTRL+\.

CTRL+Z is a simple key binding, it sends a SIGSTOP to the controlling process and the process can be managed with shell job control.

Finally, there is my favorite recent discovery, it is CTRL+\. CTRL+\ sends a more aggressive kill signal to the controlling process. As far as my research has been able to unearth CTRL+\ sends a signal 3, although I have heard many arguments for signal 11. The CTRL+\, unlike the other kill signals is a Core disposition signal, this maens that it will instruct the controlling process to terminate and dump core.

The signal sent by CTRL+\ seems to be a much more aggressive signal, more like a signal 9.

Well, enjoy your CTRL+\ invocations!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: