1MQ_OVERVIEW(7) Linux Programmer's Manual MQ_OVERVIEW(7)
2
3
4
6 mq_overview - overview of POSIX message queues
7
9 POSIX message queues allow processes to exchange data in the form of
10 messages. This API is distinct from that provided by System V message
11 queues (msgget(2), msgsnd(2), msgrcv(2), etc.), but provides similar
12 functionality.
13
14 Message queues are created and opened using mq_open(3); this function
15 returns a message queue descriptor (mqd_t), which is used to refer to
16 the open message queue in later calls. Each message queue is identi‐
17 fied by a name of the form /somename; that is, a null-terminated string
18 of up to NAME_MAX (i.e., 255) characters consisting of an initial
19 slash, followed by one or more characters, none of which are slashes.
20 Two processes can operate on the same queue by passing the same name to
21 mq_open(3).
22
23 Messages are transferred to and from a queue using mq_send(3) and
24 mq_receive(3). When a process has finished using the queue, it closes
25 it using mq_close(3), and when the queue is no longer required, it can
26 be deleted using mq_unlink(3). Queue attributes can be retrieved and
27 (in some cases) modified using mq_getattr(3) and mq_setattr(3). A
28 process can request asynchronous notification of the arrival of a mes‐
29 sage on a previously empty queue using mq_notify(3).
30
31 A message queue descriptor is a reference to an open message queue de‐
32 scription (see open(2)). After a fork(2), a child inherits copies of
33 its parent's message queue descriptors, and these descriptors refer to
34 the same open message queue descriptions as the corresponding message
35 queue descriptors in the parent. Corresponding message queue descrip‐
36 tors in the two processes share the flags (mq_flags) that are associ‐
37 ated with the open message queue description.
38
39 Each message has an associated priority, and messages are always deliv‐
40 ered to the receiving process highest priority first. Message priori‐
41 ties range from 0 (low) to sysconf(_SC_MQ_PRIO_MAX) - 1 (high). On
42 Linux, sysconf(_SC_MQ_PRIO_MAX) returns 32768, but POSIX.1 requires
43 only that an implementation support at least priorities in the range 0
44 to 31; some implementations provide only this range.
45
46 The remainder of this section describes some specific details of the
47 Linux implementation of POSIX message queues.
48
49 Library interfaces and system calls
50 In most cases the mq_*() library interfaces listed above are imple‐
51 mented on top of underlying system calls of the same name. Deviations
52 from this scheme are indicated in the following table:
53
54 Library interface System call
55 mq_close(3) close(2)
56 mq_getattr(3) mq_getsetattr(2)
57 mq_notify(3) mq_notify(2)
58 mq_open(3) mq_open(2)
5