0098-signal.sh (447B)
1 #!/bin/sh 2 3 cleanup() 4 { 5 rm -f test.txt 6 kill -KILL $pid 2>/dev/null 7 if test $1 -ne 0 8 then 9 kill -KILL $$ 10 fi 11 } 12 13 rm -f file.txt 14 trap 'cleanup 0' EXIT 15 trap 'cleanup 1' INT TERM HUP 16 17 scc make -f - <<'EOF' & 18 file.txt: 19 @touch $@ 20 @while : ; do sleep 1 ; done 21 EOF 22 pid=$! 23 24 sleep 10 && echo timeout >&2 && kill $$ 2>/dev/null & 25 timer=$! 26 27 while : 28 do 29 if test -f file.txt 30 then 31 kill $pid 32 wait $pid 33 kill $timer 34 break 35 fi 36 done 37 38 ! test -f file.txt