Here's the second part of the program:
- (This part is precisely the same as it was before).
while (numChildrenDonePlaying < kNumChildren) {
printf("At least one child still playing, so dad nods off.\n");
snooze(5);
printf("Dad wakes up! ");
}
printf("All children accounted for. Good job, dad!\n");
return 0;
}
- The primary difference here is that all child processes exit, more or less, at the same time. And while it is the case that the kernel will issue five SIGCHLD signals, not all of them prompt a dedicated execution of reapChild.
- Don't believe me? Check out the reproducible test run of this second version (where all five children finish playing pretty much much simultaneously).
myth22> ./indistinguishable-pentuplets
Let my five children play while I take a nap.
At least one child still playing, so dad nods off.
Kid #1 done playing... runs back to dad.
Kid #3 done playing... runs back to dad.
Kid #4 done playing... runs back to dad.
Kid #2 done playing... runs back to dad.
Kid #5 done playing... runs back to dad.
Dad wakes up! At least one child still playing, so dad nods off.
Dad wakes up! At least one child still playing, so dad nods off.
Dad wakes up! At least one child still playing, so dad nods off.
Dad wakes up! At least one child still playing, so dad nods off.
Dad wakes up! At least one child still playing, so dad nods off.
Dad wakes up! At least one child still playing, so dad nods off.
Dad wakes up! At least one child still playing, so dad nods off.
Dad wakes up! At least one child still playing, so dad nods off.
Dad wakes up! At least one child still playing, so dad nods off.
Dad wakes up! At least one child still playing, so dad nods off.
Dad wakes up! At least one child still playing, so dad nods off.
Dad wakes up! At least one child still playing, so dad nods off.
<ctrl-c>
myth22>