I have two scripts
foox.sh
#!/bin/bash
echo "foox"
./fooy.sh &
pid=${!}
echo "waiting on ${pid}"
timeout 4 wait ${pid}
echo "waited on ${pid} with result ${!}"
and fooy.sh
#!/bin/bash
echo "fooy.sh"
sleep 99999999
The objective is for foox.sh
to wait on fooy.sh
for 4 seconds then time out with a non zero exit code on the timeout command.
However, I get that the PID of the fooy.sh
process in a not a child process of foox.sh
which makes no sense to me, and thus the question.
Here is standard output:
foox
waiting on 48145
fooy.sh
/usr/bin/wait: line 4: wait: pid 48145 is not a child of this shell
waited on 48145 with result 48145