Solved I need to spawn background processes in MakeFile and also consider their exit codes. Scenario:
- several processes are spawned in background.
- MakeFile continue evaluation (and do not want to check spawned processes PIDs in some loop an so forth)
- Some process exits with non zero exit code
- make utility exits with non zero exit code
Naturally, I am consider to use command &
to spawn a process in background.
Problem: If command is specified like command &
then make process does not track it's exit code.
Sample 1
do:
@false & \
echo "all is normal"
%make -f exit_status_test.mk
all is normal
Sample 2
do:
@false && \
echo "all is normal"
%make -f exit_status_test.mk
*** Error code 1
Stop in /usr/home/scher/tmp/lock_testing.
Sample 1 shows that make utility does not consider exit code of the background process.
P.S. Please do not advice to store spawned processes PIDs and to check them in a loop with some sleep
delay and so forth. A need to continue evaluation of MakeFile and exit with non zero code automatically.
Solution
do:
@(echo "background command" ; (echo "[HANDLER] Prev command exits with $$?")) & \
echo "doing something"
So we can create a sequence of commands to handle exit status of background process.