1300 Chapter 62
information. (Linux provides a vaguely similar feature in the form of the magic SysRq
key; see the kernel source file Documentation/sysrq.txt for details.)
System V derivatives provide the SWTCH character. This character is used to
switch shells under shell layers, a System V predecessor to job control.
Example program
Listing 62-1 shows the use of tcgetattr() and tcsetattr() to change the terminal
interrupt character. This program sets the interrupt character to be the character
whose numeric value is supplied as the program’s command-line argument, or dis-
ables the interrupt character if no command-line argument is supplied.
The following shell session demonstrates the use of this program. We begin by
setting the interrupt character to Control-L (ASCII 12), and then verify the change
with stty:
$ ./new_intr 12
$ stty
speed 38400 baud; line = 0;
intr = ^L;
We then start a process running sleep(1). We find that typing Control-C no longer
has its usual effect of terminating a process, but typing Control-L does terminate the
process.
$ sleep 10
^C Control-C has no effect; it is just echoed
Type Control-L to terminate sleep
We now display the value of the shell $? variable, which shows the termination status of
the last command:
$ echo $?
130
We see that the termination status of the process was 130. This indicates that the
process was killed by signal 130 – 128 = 2; signal number 2 is SIGINT.
Next, we use our program to disable the interrupt character.
$ ./new_intr
$ stty Verify the change
speed 38400 baud; line = 0;
intr = <undef>;
Now we find that neither Control-C nor Control-L generates a SIGINT signal, and we
must instead use Control-\ to terminate a program:
$ sleep 10
^C^L Control-C and Control-L are simply echoed
Type Control-\ to generate SIGQUIT
Quit
$ stty sane Return terminal to a sane state