2 .\" Hey Emacs! This file is -*- nroff -*- source.
4 .\" Copyright (C) 2006 Michael Kerrisk <mtk-manpages@gmx.net>
6 .\" Permission is granted to make and distribute verbatim copies of this
7 .\" manual provided the copyright notice and this permission notice are
8 .\" preserved on all copies.
10 .\" Permission is granted to copy and distribute modified versions of this
11 .\" manual under the conditions for verbatim copying, provided that the
12 .\" entire resulting derived work is distributed under the terms of a
13 .\" permission notice identical to this one.
15 .\" Since the Linux kernel and libraries are constantly changing, this
16 .\" manual page may be incorrect or out-of-date. The author(s) assume no
17 .\" responsibility for errors or omissions, or for damages resulting from
18 .\" the use of the information contained herein.
20 .\" Formatted or processed versions of this manual, if unaccompanied by
21 .\" the source, must acknowledge the copyright and authors of this work.
23 .TH MQ_OVERVIEW 7 2006-02-25 "Linux 2.6.16" "Linux Programmer's Manual"
25 mq_overview \- Overview of POSIX message queues
27 POSIX message queues allow processes to exchange data in
29 This API is distinct from that provided by System V message queues
33 etc.), but provides similar functionality.
35 Message queues are created and opened using
37 this function returns a
38 .I message queue descriptor
40 which is used to refer to the open message queue in later calls.
41 Each message queue is identified by a name of the form
43 Two processes can operate on the same queue by passing the same name to
46 Messages are transferred to and from a queue using
50 When a process has finished using the queue, it closes it using
52 and when the queue is no longer required, it can be deleted using
54 Queue attributes can be retrieved and (in some cases) modified using
58 A process can request asynchronous notification
59 of the arrival of a message on a previously empty queue using
62 A message queue descriptor is a reference to an
63 .IR "open message queue description"
68 a child inherits copies of its parent's message queue descriptors,
69 and these descriptors refer to the same open message queue descriptions
70 as the corresponding descriptors in the parent.
71 Corresponding descriptors in the two processes share the flags
73 that are associated with the open message queue description.
75 Each message has an associated
77 and messages are always delivered to the receiving process
78 highest priority first.
79 Message priorities range from 0 (low) to
80 .I sysconf(_SC_MQ_PRIO_MAX)\ -\ 1
83 .I sysconf(_SC_MQ_PRIO_MAX)
84 returns 32768, but POSIX.1-2001 only requires
85 an implementation to support priorities in the range 0 to 31;
86 some implementations only provide this range.
87 .SS Library interfaces and system calls
90 library interfaces listed above are implemented
91 on top of underlying system calls of the same name.
92 Deviations from this scheme are indicated in the following table:
97 Library interface System call
99 mq_getattr(3) mq_getsetattr(2)
100 mq_open(3) mq_open(2)
101 mq_receive(3) mq_timedreceive(2)
102 mq_send(3) mq_timedsend(2)
103 mq_setattr(3) mq_getsetattr(2)
104 mq_timedreceive(3) mq_timedreceive(2)
105 mq_timedsend(3) mq_timedsend(2)
106 mq_unlink(3) mq_unlink(2)
109 .SH LINUX SPECIFIC DETAILS
111 POSIX message queues have been supported on Linux since kernel 2.6.6.
112 Glibc support has been provided since version 2.3.4.
113 .SS Kernel configuration
114 Support for POSIX message queues is configurable via the
115 .B CONFIG_POSIX_MQUEUE
116 kernel configuration option.
117 This option is enabled by default.
119 POSIX message queues have kernel persistence:
122 a message queue will exist until the system is shut down.
124 Programs using the POSIX message queue API must be compiled with
126 to link against the real-time library,
129 The following interfaces can be used to limit the amount of
130 kernel memory consumed by POSIX message queues:
132 .I /proc/sys/fs/mqueue/msg_max
133 This file can be used to view and change the ceiling value for the
134 maximum number of messages in a queue.
135 This value acts as a ceiling on the
139 The default and minimum value for
141 is 10; the upper limit is HARD_MAX:
142 .IR "(131072\ /\ sizeof(void\ *))"
144 This limit is ignored for privileged processes
145 .RB ( CAP_SYS_RESOURCE ),
146 but the HARD_MAX ceiling is nevertheless imposed.
148 .I /proc/sys/fs/mqueue/msgsize_max
149 This file can be used to view and change the ceiling on the
150 maximum message size.
151 This value acts as a ceiling on the
155 The default and minimum value for
157 is 8192 bytes; the upper limit is INT_MAX
158 (2147483647 on Linux/86).
159 This limit is ignored for privileged processes
160 .RB ( CAP_SYS_RESOURCE ).
162 .I /proc/sys/fs/mqueue/queues_max
163 This file can be used to view and change the system-wide limit on the
164 number of message queues that can be created.
165 Only privileged processes
166 .RB ( CAP_SYS_RESOURCE )
167 can create new message queues once this limit has been reached.
168 The default value for
170 is 256; it can be changed to any value in the range 0 to INT_MAX.
174 resource limit, which places a limit on the amount of space
175 that can be consumed by all of the message queues
176 belonging to a process's real user ID, is described in
178 .SS Mounting the message queue file system
179 On Linux, message queues are created in a virtual file system.
180 (Other implementations may also provide such a feature,
181 but the details are likely to differ.)
182 This file system can be mounted using the following commands:
187 $ mount -t mqueue none /dev/mqueue
191 The sticky bit is automatically enabled on the mount directory.
193 After the file system has been mounted, the message queues on the system
194 can be viewed and manipulated using the commands usually used for files
200 The contents of each file in the directory consist of a single line
201 containing information about the queue:
205 $ ls /dev/mqueue/mymq
206 QSIZE:129 NOTIFY:2 SIGNO:0 NOTIFY_PID:8260
207 $ mount -t mqueue none /dev/mqueue
211 These fields are as follows:
215 Number of bytes of data in all messages in the queue.
218 If this is non-zero, then the process with this PID has used
220 to register for asynchronous message notification,
221 and the remaining fields describe how notification occurs.
234 Signal number to be used for
236 .SS Polling message queue descriptors
237 On Linux, a message queue descriptor is actually a file descriptor,
238 and can be monitored using
243 This is not portable.
247 System V message queues
251 etc.) are an older API for exchanging messages between processes.
252 POSIX message queues provide a better designed interface than
253 System V message queues;
254 on the other hand POSIX message queues are less widely available
255 (especially on older systems) than System V message queues.
257 An example of the use of various message queue functions is shown in
261 .BR mq_getsetattr (2),