scc

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

0098-signal.sh (481B)


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