Control characters and signals are sort of related. You can see what the match between signals and characters are with stty -a
command in a terminal. A RHEL server I can access says:
-bash-3.2$ stty -a
speed 38400 baud; rows 24; columns 135; line = 0;
intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>; eol2 = <undef>; swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z;
rprnt = ^R; werase = ^W; lnext = ^V; flush = ^O; min = 1; time = 0;
-parenb -parodd cs8 -hupcl -cstopb cread -clocal -crtscts -cdtrdsr
-ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl ixon -ixoff -iuclc -ixany -imaxbel -iutf8
opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0
isig icanon iexten echo echoe echok -echonl -noflsh -xcase -tostop -echoprt echoctl echoke
Some of that is related to the TTY and what it does to input, other stuff to signals. The parts for signals:
intr = ^C; quit = ^\; susp = ^Z;
That means SIGINT is control-C, SIGQUIT is control-backslash and SIGSTOP is control-Z. You can reassign any or all of those, if you like. See man stty
.
The other control characters like erase
or werase
are intercepted and used by the terminal driver itself. Like when you backspace, the terminal driver erases a character from the screen and from the input stream. The "mode" of the terminal driver (raw or cooked, possibly partially cooked) makes a difference as well. Text editors like vim
and emacs
make heavy use of control characters, and they don't get a SIGINT or SIGQUIT or whatever when you type those control characters. A program can set the TTY to "raw mode" and just read the bytes without interpretation by the terminal driver.