scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | Submodules | README | LICENSE

0098-signal.sh (466B)


      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 	trap - EXIT
     12 }
     13 
     14 rm -f file.txt
     15 trap 'cleanup 0' EXIT
     16 trap 'cleanup 1' INT TERM HUP
     17 
     18 $EXEC scc make -f - <<'EOF' &
     19 file.txt:
     20 	@touch $@
     21 	@while : ; do sleep 1 ; done
     22 EOF
     23 pid=$!
     24 
     25 sleep 10 && echo timeout >&2 && kill $$ 2>/dev/null &
     26 timer=$!
     27 
     28 while :
     29 do
     30 	if test -f file.txt
     31 	then
     32 		kill $pid
     33 		wait $pid
     34 		kill $timer
     35 		break
     36 	fi
     37 done
     38 
     39 ! test -f file.txt