ptg10805159
670 Advanced IPC Chapter 17
Exercises
17.1 We chose to use UNIX domain datagram sockets in Figure17.3, because they retain
message boundaries. Describe the changes that would be necessary to use regular pipes
instead. How can we avoid copying the messages two extra times?
17.2 Write the following program using the file descriptor passing functions from this chapter
and the parent–child synchronization routines from Section 8.9. The program callsfork,
and the childopens an existing file and passes the open descriptor to the parent. The child
then positions the file usinglseekand notifies the parent. The parent reads the file’s
current offset and prints it for verification. If the file was passed from the child to the
parent as we described, they should be sharing the same file table entry, so each time the
child changes the file’s current offset, that change should also affect the parent’s descriptor.
Have the child position the file to a different offset and notify the parent again.
17.3 In Figures 17.20 and 17.21, we differentiated between declaring and defining the global
variables. What is the difference?
17.4 Recode thebuf_argsfunction (Figure17.23), removing the compile-time limit on the size
of theargvarray.Use dynamic memory allocation.
17.5 Describe ways to optimize the functionloopin Figure17.29 and Figure17.30. Implement
your optimizations.
17.6 In theserv_listenfunction (Figure17.8), we unlink the name of the file representing
the UNIX domain socket if the file already exists.To avoid unintentionally removing a file
that isn’t a socket, we could callstatfirst to verify the file type. Explain the two problems
with this approach.
17.7 Describe two possible ways to pass morethan one file descriptor with a single call to
sendmsg.Try them out to see if they aresupported by your operating system.