ptg10805159
Appendix C Chapter 15 Solutions 935
The following table shows the values calculated for our four platforms.
Platform Pipe Capacity (bytes)
FreeBSD 8.0 65,536
Linux 3.2.0 65,536
Mac OS X 10.6.8 16,384
Solaris 10 16,384
These values can differ from the corresponding PIPE_BUF values, because
PIPE_BUFis defined to be the maximum amount of data that can be written to a
pipeatomically.Here, we calculate the amount of data that a pipe can hold
independent of any atomicity constraints.
14.10 Whether the program in Figure14.27 updates the last-access time for the input
file depends on the operating system and the type of file system in which the file
resides. On all four platforms, the last-access time is updated when the file
resides in the default file system type for the given operating system.
Chapter 15
15.1 If the write end of the pipe is never closed, the reader never sees an end of file.
The pager program blocks forever reading from its standardinput.
15.2 The parent terminates right after writing the last line to the pipe. The read end of
the pipe is automatically closed when the parent terminates. But the parent is
probably running ahead of the child by one pipe buffer,since the child (the pager
program) is waiting for us to look at a page of output. If we’rerunning a shell,
such as the Korn shell, with interactive command-line editing enabled, the shell
probably changes the terminal mode when our parent terminates and the shell
prints a prompt. This undoubtedly interferes with the pager program, which has
also modified the terminal mode. (Most pager programs set the terminal to
noncanonical mode when awaiting input to proceed to the next page.)
15.3 Thepopenfunction returns a file pointer because the shell is executed. But the
shell can’t execute the nonexistent command, so it prints
sh: line 1: ./a.out: No such file or directory
on the standarderror and terminates with an exit status of 127 (although the
value depends on the type of shell). pclosereturns the termination status of
the command as it is returned bywaitpid.
15.4 When the parent terminates, look at its termination status with the shell. For the
Bourne shell, Bourne-again shell, and Korn shell, the command isecho $?.The
number printed is 128 plus the signal number.
15.5 First add the declaration
FILE *fpin, *fpout;