Notes On Specific Signals
Signals are highly nonportable. Their behavior varies quite a bit from one system to another. Nonetheless, it is possible to state some generalizations about each one.
SIGINT—Software Interrupt Signal
SIGINT
is an interrupt signal. It is usually generated by pressing ^C from the keyboard. The specific key can be changed using stty
. The signal can, of course, also be generated via the kill
command. If the SIGINT
handler is set to SIG_DFL
, a SIGINT
will cause Expect to die without evaluating exit
.
By default, Expect traps SIGINT
and defines it to call exit
. This association is defined with the command "trap exit SIGINT
“, which is evaluated when Expect starts. If you redefine the exit
procedure, the trap will invoke your exit
.[53]
If Expect is in raw mode, the ^C will not automatically generate a SIGINT
but will instead be handled like any other character. For example, interact
implicitly puts the terminal in raw mode so that a ^C is sent to the spawned process. You can define a pattern to match ^C and generate a SIGINT
using kill
, but that is not common practice and would be confusing to users.
In Chapter 9 (p. 219), I described how the debugger is enabled if Expect is started with the -D
flag. Part of what -D
does is to redefine the behavior of SIGINT
as follows:
trap {exp_debug 1} SIGINT
Pressing ^C will then invoke the debugger rather than causing Expect to exit. If you want to redefine SIGINT
so that it performs some other action (and does not exit), you can ...
Get Exploring Expect now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.