trap.sh | trap (CTRL-C) is signal 2 (SIGINT)
cat trap.sh
#!/bin/usr/env bash
trap 'increment' 2
increment()
{
echo "Caught SIGINT ..."
X=`expr ${X} + 500`
if [ "${X}" -gt "2000" ]
then
echo "Okay, I'll quit ..."
exit 1
fi
}
### main script
X=0
while :
do
echo "X=$X"
X=`expr ${X} + 1`
sleep 1
done
#!/bin/usr/env bash
trap 'increment' 2
increment()
{
echo "Caught SIGINT ..."
X=`expr ${X} + 500`
if [ "${X}" -gt "2000" ]
then
echo "Okay, I'll quit ..."
exit 1
fi
}
### main script
X=0
while :
do
echo "X=$X"
X=`expr ${X} + 1`
sleep 1
done
Here is a table of some of the common interrupts:
Number | SIG | Meaning |
---|---|---|
0 | 0 | On exit from shell |
1 | SIGHUP | Clean tidyup |
2 | SIGINT | Interrupt |
3 | SIGQUIT | Quit |
6 | SIGABRT | Abort |
9 | SIGKILL | Die Now (cannot be trap'ped) |
14 | SIGALRM | Alarm Clock |
15 | SIGTERM | Terminate |
Comments
Post a Comment