You should just do:
while kill -0 $PID >/dev/null 2>&1
do
done
The loop condition checks the output status of the last command - in this case kill.
The meaning of the "last" is that you can write:
while sleep 1
echo Testing again
kill -0 $PID >/dev/null 2>&1
do
done
It also checks the status of the output kill(and killonly).
source
share