Kill a process and wait for the process to exit
No. What you can do is write a loop with kill -0 $PID
. If this call fails ($? -ne 0
), the process has terminated:
while kill -0 $PID; do sleep 1done
(kudos to qbolec for the code)
Related:
Use wait
(bash builtin) to wait for the process to finish:
pkill <previous_pid> wait <previous_pid>