Dealing with Signals

A program can deal with a signal in three ways:

  • Do nothing and let the default action occur. This is the simplest method for a program to deal with a signal because it requires no extra code.

  • Ignore the signal and continue executing. This method is not the same as doing nothing because ignoring a signal requires the program to have some code that explicitly ignores the signal.

  • Catch the signal and perform some signal-specific commands. This method requires the program to define a function that is executed when a signal is received. This is the most complex and powerful method of dealing with a signal.

The first method is the default behavior for all shell scripts. All the scripts that you have looked at thus far handle signals ...

Get Sams Teach Yourself Shell Programming in 24 Hours, Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.