#! /bin/sh # Example to show signal handling for (( i = 1; i < 32; ++i )) do trap "echo caught signal $i" $i done echo My process ID is $$ echo "Now copy and paste the following into another window:" echo 'for ((i=0;i < 32; ++i));do if ((i==9 || i==19));then let ++i;fi;echo Sending signal $i:;kill -$i '$$';sleep 1;done' echo Then try pasting this code, and understand why this process terminates: echo 'for ((i=0;i < 32; ++i));do echo Sending signal $i:;kill -$i '$$';sleep 1;done' # So how can we terminate it? # Note: # The colon `:' is the null statement that can be used wherever the # syntax requires a statement. It returns the value 0 (i.e., true). # In this case, it gives us an infinite loop. # Try: # $ help : while : do sleep 1 done # Try running this in one window, and in another window, type this: # for ((i=0;i < 32; ++i));do if ((i==9 || i==19));then let ++i;fi;echo Sending signal $i:;kill -$i 21306;sleep 1;done # Of course, instead of 21306, put the process ID of this process. # Then try removing the "if ((i==9 || i==19));then let ++i;fi;" statement, # and run it again.