blob: bfe153b7a65d91fc8e3be738041e7cd6de7b61da [file] [log] [blame]
#!/bin/sh
#
# pkill the process given on the command line, first with SIGTERM,
# then after max 2 seconds, if it still lives, using SIGKILL. Don't return
# until the process is dead.
#
if [ "$#" = 0 ]; then
echo "usage: $0 <pgrep-options...>" >&2
exit 1
fi
echo -n "Stopping $*: " >&2
if [ -n "$2" ]; then
baby=$2
else
baby=$1
fi
babysitter="babysit [0-9]+ ($baby)(\$| )"
pkill -f "$babysitter"
pkill "$@"
for d in $(seq 20); do
if ! { pgrep -f "$babysitter" || pgrep "$@"; } >/dev/null; then
echo done >&2
exit 0
fi
usleep 100000
echo -n "." >&2
done
pkill -9 -f "$babysitter"
pkill -9 "$@"
echo done >&2