Troubleshooting
Problem
Trapping CTRL-C and CTRL-Z in UNIX ksh - What are the control-key signals?
Symptom
PART: UNIX Korn Shell
I need to trap control-keys in the Korn Shell, so
my users can not break to the command prompt from the Yantra application, but I
don't know what signals are sent by the CTRL-C and CTRL-Z key combinations.
Cause
Resolving The Problem
When you type CTRL-C, you tell the shell to send the INT (for "interrupt")
signal to the current job; [CTRL-Z] sends TSTP (on most systems, for "terminal
stop"). You can also send the current job a QUIT signal by typing CTRL-\
(control-backslash); this is sort of like a "stronger" version of [CTRL-C]. [7]
You would normally use [CTRL-] when (and only when) [CTRL-C] doesn't work.
[7] [CTRL-]\ can also cause the shell to leave a file called core in your
current directory. This file contains an image of the process to which you sent
the signal; a programmer could use it to help debug the program that was
running. The file's name is a (very) old-fashioned term for a computer's
memory. Other signals leave these "core dumps" as well; you should feel free to
delete them unless a systems programmer tells you otherwise.
As we'll see
soon, there is also a "panic" signal called KILL that you can send to a process
when even [CTRL-] doesn't work. But it isn't attached to any control key, which
means that you can't use it to stop the currently running process. INT, TSTP,
and QUIT are the only signals you can use with control keys. [8]
[8] Some
BSD-derived systems have additional control-key signals.
You can customize
the control keys used to send signals with options of the stty(1) command.
These vary from system to system-consult your man page for the command-but the
usual syntax is stty signame char. signame is a name for the signal that,
unfortunately, is often not the same as the names we use here. Table 1.7
<ch01_09.htm> in Chapter 1, Korn Shell Basics <ch01_01.htm> lists stty names
for signals found on all versions of UNIX. char is the control character, which
you can give in the same notation we use. For example, to set your INT key to
[CTRL-X] on most systems, use:
stty intr ^X
Now that we've told you how
to do this, we should add that we don't recommend it. Changing your signal keys
could lead to trouble if someone else has to stop a runaway process on your
machine.
Most of the other signals are used by the operating system to
advise processes of error conditions, like a bad machine code instruction, bad
memory address, or division by zero, or "interesting" events such as a user
logging out or a timer ("alarm") going off. The remaining signals are used for
esoteric error conditions that are of interest only to low-level systems
programmers; newer versions of UNIX have more and more arcane signal
types.
More information about the Korn Shell here:
http://www.unix.org.ua/orelly/unix/ksh/index.htm
Historical Number
PRI49663
Product Synonym
[<p><b>]Fact[</b><p>];
Was this topic helpful?
Document Information
Modified date:
16 June 2018
UID
swg21525522