Skip to content

Instantly share code, notes, and snippets.

@hashmap
Last active December 16, 2015 13:57
Show Gist options
  • Save hashmap/046c0efb6abe21702a5b to your computer and use it in GitHub Desktop.
Save hashmap/046c0efb6abe21702a5b to your computer and use it in GitHub Desktop.
Manual test for story #108987020
package main
import (
"fmt"
"os"
"os/signal"
"strconv"
"time"
)
func main() {
fmt.Println(strconv.Itoa(os.Getpid()))
signal.Ignore()
for {
time.Sleep(5 * time.Second)
}
}
function pid_exists() {
ps -p $1 &> /dev/null
}
PID=$(head -1 $1)
if [ ! -z $PID ] && pid_exists $PID; then
kill $PID
fi
TRIES=0
while [ -e /proc/$PID ]
do
TRIES=$(( $TRIES + 1 ))
if [ $TRIES -gt 100 ]; then
kill -9 $PID
fi
sleep 0.1
done
rm -f $PIDFILE
$ go run immortal.go > pid &
$ ./stop.sh pid
signal: killed
[1]+ Exit 1 go run immortal.go > pid
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment