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

process=$1
retry_count=20

killall $process || true

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

echo "wait process $process exit timeout"
exit 1
