Why should we check WIFEXITED after wait in order to kill child processes in Linux system call?

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:

Leave a Comment