How to check whether a background job is alive? (bash)
You can get the PID of the most recent background job with $!
. You could then check the exit status of ps to determine if that particular PID is still in the process list. For example:
sleep 30 &
if ps -p $! >&-; then
wait $!
else
jobs
fi
You can check if a signal is deliverable
./script2 &
myPid=$!
sleep 5
if kill -0 "$myPid"; then
script3 &
wait
fi