When killing a daemon, instead of using kill -9 to check the process was
terminated, use kill -0. Should the pid of the process be reused
immediately after, it would be wrong to kill the new process. Worst case
scenario the kill_daemon function returns before the process is
confirmed to be killed but this is not treated as an error and is
unlikely to cause any problem.
Signed-off-by: Loic Dachary <loic-201408@dachary.org>
local dir=$1
for pidfile in $(find $dir | grep '\.pid') ; do
pid=$(cat $pidfile)
+ signal=9
for try in 0 1 1 1 2 3 ; do
- kill -9 $pid 2> /dev/null || break
+ kill -$signal $pid 2> /dev/null || break
+ signal=0
sleep $try
done
done