March 2002
Beginner
504 pages
10h 47m
English
| 1: | The following is the main body of the “live” script presented earlier in this chapter. Change the script such that SIGQUIT causes it to exit after the wait command returns.
# main()
trap CleanUp 2 3 15
trap Init 1
PROG=$1
Init
while : ;
do
wait $!
$PROG &
done
|
| A1: | Here is a possible implementation:
trap CleanUp 2 15
trap Init 1
trap "quit=true" 3
PROG="$1"
Init
while : ;
do
wait $!
if [ "$quit" = true ] ; then exit 0 ; fi
$PROG &
done
|
| 2: | Add a signal handler to the timer script to handle SIGINT. |
| A2: | Here is a possible implementation:
#! /bin/sh AlarmHandler() { echo "Got SIGALARM, cmd took too long." KillSubProcs exit 14 } IntHandler() { echo "Got SIGINT, user interrupt." KillSubProcs exit 2 } KillSubProcs() { kill ${CHPROCIDS:-$!} ... |
Read now
Unlock full access