ptg10805159
556 Interprocess Communication Chapter 15
client ... client
well-known
FIFO
server
readrequests
client-specific
FIFO
client-specific
FIFO
write
replies
write
replies
readreplies readreplies
write
requests
write
requests
Figure 15.23Client–server communication using FIFOs
server also must catchSIGPIPE,since it’s possible for a client to send a request and
terminate beforereading the response, leaving the client-specific FIFO with one writer
(the server) and no reader.
With the arrangement shown in Figure15.23, if the server opens its well-known
FIFO read-only (since it onlyreadsfromit) each time the number of clients goes from 1
to 0, the server willreadan end of file on the FIFO.To prevent the server from having
to handle this case, a common trick is just to have the serveropenits well-known FIFO
for read–write. (See Exercise 15.10.)
15.6 XSI IPC
The three types of IPC that we call XSI IPC—message queues, semaphores, and shared
memory — have many similarities. In this section, we cover these similar features; in the
following sections, we look at the specific functions for each of the three IPC types.
The XSI IPC functions arebased closely on the System V IPC functions. These three types of
IPC originated in the 1970s in an internal AT&T version of the UNIX System called ‘‘Columbus
UNIX.’’These IPC features werelater added to System V.They areoften criticized for
inventing their own namespace instead of using the file system.
15.6.1 Identifiersand Keys
Each IPC structure(message queue, semaphore, or shared memory segment) in the
kernel is referred to by a non-negative integeridentifier.Tosend a message to or fetch a
message from a message queue, for example, all we need know is the identifier for the
queue. Unlike file descriptors, IPC identifiers arenot small integers. Indeed, when a