Text-only Table of Contents (frame/ no frame)
(28) Signals Previous Top Next

Delivering and Trapping Signals

Unix signals (software interrupts) can be sent as asynchronous events to shell scripts, just as they can to any other program. The default behaviour is to ignore some signals and immediately exit on others. Scripts may detect signals and divert control to a handler function or external program. This is often used to perform clean-up actions before exiting, or restart certain procedures. Execution resumes where it left off, if the signal handler returns. Signal traps must be set separately inside of shell functions. Signals can be sent to a process with kill.
trap handler sig ...
handler is a command to be read (evaluated first) and executed on receipt of the specified sigs. Signals can be specified by name or number (see kill(1)) e.g. HUP, INT, QUIT, TERM. A Ctrl-C at the terminal generates a INT.

Example: ex8 display, text

Exit handlers can be defined to clean up temporary files or reset the state of devices. This can be useful if the script has multiple possible exit points.

Previous Top Next


signals.src  last modified Mar 26, 2010 Introduction Table of Contents
(frame/no frame)
Printable
(single file)
© Dartmouth College