#!/bin/bash
# parameter 1: process name

process=$1
retry_count=60

killall $process || true

counter=0
while [ $counter -lt $retry_count ]; do
	pgrep -x $process >/dev/null 2>&1
	ret=$?
	if [ "$ret" != "0" ]; then
		echo "process $process already exit"
		exit 0
	fi
	((counter += 1))
	sleep 1
	killall -9 $process || true
	echo "wait process $process exit for $counter-th time..."
done

echo "wait process $process exit timeout"
exit 1
