handle ctrl-c

This commit is contained in:
Mark McGranaghan 2012-10-11 08:00:42 -07:00
parent e34108a8d1
commit deafc3a0bf
2 changed files with 16 additions and 7 deletions

View File

@ -27,10 +27,10 @@ func main() {
fmt.Println("going") fmt.Println("going")
}() }()
// Since our two goroutines are running asynchrously // Our two goroutines are running asynchrously in
// in separate goroutines now, execution immediatly // separate goroutines now, so execution falls through
// falls through to here. This `Scanln` code requires // to here. This `Scanln` code requires we press a key
// that we press a key before the program exits. // before the program exits.
var input string var input string
fmt.Scanln(&input) fmt.Scanln(&input)
fmt.Println("done") fmt.Println("done")

View File

@ -1,12 +1,21 @@
#!/bin/bash #!/bin/bash
TRAPPING=0
trap "{ echo finishing; TRAPPING=1; }" SIGINT
while : while :
do do
tools/build tools/build
if [ "$?" == "0" ]; then RET=$?
if [ $RET -eq 0 ]; then
echo "success" echo "success"
else else
echo "error" echo "error: $RET"
fi
if [ $TRAPPING -eq 0 ]; then
sleep 1
else
echo "done"
exit 0
fi fi
sleep 1
done done