I need to start a process in the background, then continue and run other processes. I want to exit the script as soon as my myBackgroundProcess process ends with non 0 exit code. (or soon ish when i check in the loop).
#!/usr/bin/env bash
set -e
nohup myBackgroundProcess &
myPid=$!
for i in {1..30000}; do
sleep 10
someProcessDoingStuff
wait ${myPid} #this is blocking, but i want to continue the loop
done
so I would like some type of non blocking way to check the exit code of a process by its pid, if it has finished.
its is close this issue WAIT for "any process" to finish but not 100% same, however the issue gives a clue as to how one might implement your own nonblocking wait
A possible work around
$(sleep 10 ; echo $? > exitCode.txt) &
any better solutions, or issues with the above. 1 issue is 1 loose the std out of the process.
so i want to start a process in the background, keep its std out err, and have the exit code written to a file. with out modding the process its self.