S Y S T E M V M E S S A G E Q U E U E S
This chapter describes System V message queues. Message queues allow
processes
to exchange data in the form of messages. Although message queues are similar to
pipes and FIFOs in some respects, they also differ in important ways:
z
The handle used to refer to a message queue is the identifier returned by a call
to msgget(). These identifiers are not the same as the file descriptors used for
most other forms of I/O on UNIX systems.
z
Communication via message
queues is message-oriented; that is, the reader
receives whole messages, as written by the writer. It is not possible to read part
of a message, leaving
the remainder in the queue, or to read multiple messages
at a time. This contrasts with pipes, which provide an undifferentiated stream
of bytes (i.e., with pipes, the reader can read an arbitrary
number of bytes at a
time, irrespective of the size of data blocks written by the writer).
z
In addition to containing data, each message has an integer type. Messages can
be retrieved from a
queue in first-in, first-out order or retrieved by type.
At the end of this chapter (Section 46.9), we summarize a number of limitations of
System V message queues. These limitations lead us to the conclusion that, where
possible, new applications should avoid the use of System V message queues in
favor of other
IPC mechanisms such as FIFOs, POSIX message queues, and sockets.
However, when message queues were initially devised,
these alternative mecha-
nisms were unavailable or were not widespread across UNIX implementations.
938
Chapter 46
Consequently, there are various existing applications that employ message queues,
and this fact forms one of the primary motivations for describing them.
Chia sẻ với bạn bè của bạn: