Exercises
15.1 | In the program shown in Figure 15.6, remove the close right before the waitpid at the end of the parent code. Explain what happens. |
15.2 | In the program in Figure 15.6, remove the waitpid at the end of the parent code. Explain what happens. |
15.3 | What happens if the argument to popen is a nonexistent command? Write a small program to test this. |
15.4 | In the program shown in Figure 15.18, remove the signal handler, execute the program, and then terminate the child. After entering a line of input, how can you tell that the parent was terminated by SIGPIPE? |
15.5 | In the program in Figure 15.18, use the standard I/O library for reading and writing the pipes instead of read and write. |
15.6 | The Rationale for POSIX.1 gives as one of the reasons for adding the waitpid function that most pre-POSIX.1 systems can't handle the following:What happens in this code if waitpid isn't available and wait is used instead? |
15.7 | Explain how select and poll handle an input descriptor that is a pipe, when the pipe is closed by the writer. To determine the answer, write two small test programs: one using select and one using poll.Redo this exercise, looking at an output descriptor that is a pipe, when the read end is closed. |
15.8 | What happens if the cmdstring executed by popen with a type of "r" writes to its standard error? |
15.9 | Since popen invokes a shell to execute its cmdstring argument, what happens when cmdstring terminates? (Hint: draw all the processes involved.) |
15.10 | POSIX.1 specifically states that opening a FIFO for readwrite is undefined. Although most UNIX systems allow this, show another method for opening a FIFO for both reading and writing, without blocking. |
15.11 | |
15.13 | Describe how to build a linked list of data objects in a shared memory segment. What would you store as the list pointers? |
15.14 | Draw a time line of the program in Figure 15.33 showing the value of the variable i in both the parent and child, the value of the long integer in the shared memory region, and the value returned by the update function. Assume that the child runs first after the fork. |
Section 15.9 | instead of the shared memory-mapped region. |
Figure 15.33 | using the XSI semaphore functions from |
Section 15.8 | to alternate between the parent and the child. |
Figure 15.33 | using advisory record locking to alternate between the parent and the child. |