Unformatted text preview: the exit function or executing a return statement), then mysystem returns the command exit status. For example, if command terminates 446 CHAPTER 8. EXCEPTIONAL CONTROL FLOW by calling exit(8), then system returns the value 8. Otherwise, if command terminates abnormally, then mysystem returns the status returned by the shell. Homework Problem 8.18 [Category 1]: One of your colleagues is thinking of using signals to allow a parent process to count events that occur in a child process. The idea is to notify the parent each time an event occurs by sending it a signal, and letting the parent’s signal handler increment a global counter variable, which the parent can then inspect after the child has terminated. However, when he runs the test program in Figure 8.35 on his system, he discovers that when the parent calls printf, counter always has a value of 2, even though the child has sent ﬁve signals to the parent. Perplexed, he comes to you for help. Can you explain the bug?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 2...
View Full Document