wait
returning >= 0
tells you a child process has terminated (and that calling wait
didn’t fail), but it does not tell you whether that process terminated successfully or not (or if it was signalled).
But, here, looking at your code, it’s fairly obvious the program does care about whether the child process that terminated did so successfully or not:
fprintf( stderr,"Child failed. Killing all running children.\n");
So, the program needs to do further tests on the status
structure that was populated by wait
:
WIFEXITED(status)
: did the process exit normally? (as opposed to being signalled).WEXITSTATUS(status) == 0
: did the process exit with exit code 0 (aka “success”). For more information, see: Meaning of exit status 1 returned by linux command.