ptg10805159
532 Advanced I/O Chapter 14
Exercises
14.1 Write a test program that illustrates your system’s behavior when a process is blocked
while trying to write lock a range of a file and additional read-lock requests aremade. Is
the process requesting a write lock starved by the processes read locking the file?
14.2 Take a look at your system’s headers and examine the implementation ofselectand the
fourFD_macros.
14.3 The system headers usually have a built-in limit on the maximum number of descriptors
that thefd_setdata type can handle. Assume that we need to increase this limit to
handle up to 2,048 descriptors. How can we do this?
14.4 Comparethe functions provided for signal sets (Section 10.11) and thefd_setdescriptor
sets. Also comparethe implementation of the two on your system.
14.5 Implement the functionsleep_us,which is similar tosleep,but waits for a specified
number of microseconds. Use eitherselectorpoll.Comparethis function to the BSD
usleepfunction.
14.6 Can you implement the functions TELL_WAIT, TELL_PARENT, TELL_CHILD,
WAIT_PARENT,andWAIT_CHILDfrom Figure10.24 using advisory recordlocking instead
of signals? If so, code and test your implementation.
14.7 Determine the capacity of a pipe using nonblocking writes. Comparethis value with the
value ofPIPE_BUFfrom Chapter 2.
14.8 Rewrite the program in Figure14.21 to make it a filter: read from the standardinput and
write to the standardoutput, but use the asynchronous I/O interfaces. What must you
change to make it work properly? Keep in mind that you should get the same results
whether the standardoutput is attached to a terminal, a pipe, or a regular file.
14.9 Recall Figure14.23. Determine the break-even point on your system whereusingwritev
is faster than copying the data yourself and using a singlewrite.
14.10 Run the program in Figure14.27 to copy a file and determine whether the last-access time
for the input file is updated.
14.11 In the program from Figure14.27,closethe input file after callingmmapto verify that
closing the descriptor does not invalidate the memory-mapped I/O.