The Linux Programming Interface

(nextflipdebug5) #1
Solutions to Selected Exercises 1435

Chapter 55


55-1. The following hold for flock() on Linux:
a) A series of shared locks can starve a process waiting to place an exclusive lock.
b) There are no rules regarding which process is granted the lock. Essentially,
the lock is granted to the process that is next scheduled. If that process
happens to be one that obtains a shared lock, then all other processes
requesting shared locks will also be able to have their requests granted
simultaneously.
55-2. The flock() system call doesn’t detect deadlock. This is true of most flock()
implementations, except those that implement flock() in terms of fcntl().
55-4. In all except early (1.2 and earlier) Linux kernels, the two types of locking operate
independently, and have no affect on one another.

Chapter 57


57-4. On Linux, the sendto() call fails with the error EPERM. On some other UNIX systems,
a different error results. Some other UNIX implementations don’t enforce this
constraint, letting a connected UNIX domain datagram socket receive datagrams
from a sender other than its peer.

Chapter 59


59-1. A solution is provided in the files read_line_buf.h and read_line_buf.c in the sockets
subdirectory in the source code distribution for this book.
59-2. A solution is provided in the files is_seqnum_v2_sv.c, is_seqnum_v2_cl.c, and
is_seqnum_v2.h in the sockets subdirectory in the source code distribution for this
book.
59-3. A solution is provided in the files unix_sockets.h, unix_sockets.c, us_xfr_v2.h,
us_xfr_v2_sv.c, and us_xfr_v2_cl.c in the sockets subdirectory in the source code
distribution for this book.
59-5. In the Internet domain, datagrams from a nonpeer socket are silently discarded.

Chapter 60


60-2. A solution is provided in the file sockets/is_echo_v2_sv.c in the source code
distribution for this book.

Chapter 61


61-1. Since the send and receive buffers for a TCP socket have a limited size, if the client
sent a large quantity of data, then it might fill these buffers, at which point a further
write() would (permanently) block the client before it read any of the server’s
response.
61-3. A solution is provided in the file sockets/sendfile.c in the source code distribution
for this book.
Free download pdf