Given a list of signals (kill -l can give you), I want to know all the ctrl + key that can raise one of them. For example, the ctrl+c raises SIGINT when running on terminal a foreground process. Is it possible ? Where is the ctrl+key mapped on system ? If has a C
function that shows me it is better.

- 970
- 12
- 27
-
Some of this is in the terminal driver, some of it is in libraries like `readline`. – Barmar May 27 '16 at 20:07
-
`readline` is programmable using `.inputrc`. And applications that use it, like `bash`, often have their own configuration commands. – Barmar May 27 '16 at 20:07
-
`stty -a` will show all bindings handled by the terminal driver in caret notation (e.g. `intr = ^C` showing interrupt is Ctrl+C). You can change the bindings with `stty` for the current terminal. – that other guy May 27 '16 at 20:16
-
See also: http://stackoverflow.com/questions/6764265/which-signal-does-ctrl-x-send-when-used-in-a-terminal – ninjalj May 28 '16 at 00:57
2 Answers
The description of Linux terminal input handling is found in man tcsetattr
, which is the function you would use to configure the mapping for cooked input. (Look for the c_cc
array for the list of special characters.) The Linux terminal is based on the Posix standard but it has a number of extensions. (The list of special characters is in §11.1.9 of Posix, but you should also read the preceding sections for a complete understanding of the terminal programming model.)
There are three signals which the terminal driver will send in response to control characters:
SIGINT
(VINTR
, default Ctrl-C)SIGQUIT
(VQUIT
, default Ctrl-\)SIGTSTP
(VSUSP
, default Ctrl-Z)
If you set the terminal to raw mode (with the same function) then you will have to issue the signals yourself (if you want to) and you can use whatever mechanism you choose to decide what triggers each signal.
The readline
library (used by many shells) puts the terminal into raw mode while it is reading, then does its own character mapping [Note 2]. However, when bash
hands the terminal over to a command application, the terminal is restored to default mode [Note 1], so the mapping is controlled by the terminal driver as explained in the tcsetattr
documention.
If you want to use readline
, you will need to consult its documentation.
Most applications using ncurses
also start by putting the terminal into raw mode.
Notes
This is actually a bit imprecise, since commands can modify the terminal mode. (See
man stty
, for example.) If some command changes a control character, that becomes part of the mode which will be passed to the next command.readline
doesn't turn offVINTR
handling, soSIGINT
can be sent even ifreadline
is being used; this will obey the current terminal setting. But it does turn off the other control characters.

- 234,347
- 28
- 237
- 341
Ctrl-Z in most Unix shells will suspend processes (SIGTSTP), and such suspended processes can be run in the background with bg
or brought back to the foreground with fg
. Processes cannot avoid the suspend signal unless they catch Ctrl-Z in, say, raw mode.
Ctrl-S stops terminal output, while Ctrl-Q restarts it.
The rest is dependent on your shell or readline
config and I recommend reading your shell's documentation for further information.

- 63
- 1
- 7