Chapter 8
8.1 | To simulate the behavior of the child closing the standard output when it exits, add the following line before calling exit in the child:To see the effects of doing this, replace the call to printf with the lines
|
8.2 | Consider Figure C.7.Figure C.7. Incorrect use of vforkWhen vfork is called, the parent's stack pointer points to the stack frame for the f1 function that calls vfork. Figure C.8 shows this. Figure C.8. Stack frames when vfork is called![]() |
8.3 | In Figure 8.13, we have the parent output first. When the parent is done, the child writes its output, but we let the parent terminate. Whether the parent terminates or whether the child finishes its output first depends on the kernel's scheduling of the two processes (another race condition). When the parent terminates, the shell starts up the next program, and this next program can interfere with the output from the previous child.We can prevent this from happening by not letting the parent terminate until the child has also finished its output. Replace the code following the fork with the following:We won't see this happen if we let the child go first, since the shell doesn't start the next program until the parent terminates. |
8.4 | The same value (/home/sar/bin/testinterp) is printed for argv[2]. The reason is that execlp ends up calling execve with the same pathname as when we call execl directly. Recall Figure 8.15. |
8.5 | |
8.6 | The program in Figure C.9 creates a zombie.Figure C.9. Create a zombie and look at its status with psZombies are usually designated by ps(1) with a status of Z:
|