]>
Commit | Line | Data |
---|---|---|
80a99f39 MK |
1 | '\" t |
2 | .\" Hey Emacs! This file is -*- nroff -*- source. | |
3 | .\" | |
c11b1abf | 4 | .\" Copyright (C) 2006 Michael Kerrisk <mtk.manpages@gmail.com> |
80a99f39 MK |
5 | .\" |
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. | |
9 | .\" | |
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. | |
c13182ef | 14 | .\" |
80a99f39 MK |
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 | |
c13182ef MK |
18 | .\" the use of the information contained herein. |
19 | .\" | |
80a99f39 MK |
20 | .\" Formatted or processed versions of this manual, if unaccompanied by |
21 | .\" the source, must acknowledge the copyright and authors of this work. | |
22 | .\" | |
d9343c5c | 23 | .TH MQ_OVERVIEW 7 2006-02-25 "Linux" "Linux Programmer's Manual" |
80a99f39 | 24 | .SH NAME |
c13182ef | 25 | mq_overview \- Overview of POSIX message queues |
80a99f39 | 26 | .SH DESCRIPTION |
c13182ef | 27 | POSIX message queues allow processes to exchange data in |
80a99f39 | 28 | the form of messages. |
91091371 MK |
29 | This API is distinct from that provided by System V message queues |
30 | .RB ( msgget (2), | |
31 | .BR msgsnd (2), | |
32 | .BR msgrcv (2), | |
33 | etc.), but provides similar functionality. | |
34 | ||
80a99f39 MK |
35 | Message queues are created and opened using |
36 | .BR mq_open (3); | |
37 | this function returns a | |
38 | .I message queue descriptor | |
39 | .RI ( mqd_t ), | |
40 | which is used to refer to the open message queue in later calls. | |
c13182ef | 41 | Each message queue is identified by a name of the form |
80a99f39 MK |
42 | .IR /somename . |
43 | Two processes can operate on the same queue by passing the same name to | |
63f6a20a | 44 | .BR mq_open (3). |
80a99f39 MK |
45 | |
46 | Messages are transferred to and from a queue using | |
47 | .BR mq_send (3) | |
48 | and | |
49 | .BR mq_receive (3). | |
50 | When a process has finished using the queue, it closes it using | |
c13182ef | 51 | .BR mq_close (3), |
80a99f39 MK |
52 | and when the queue is no longer required, it can be deleted using |
53 | .BR mq_unlink (3). | |
54 | Queue attributes can be retrieved and (in some cases) modified using | |
55 | .BR mq_getattr (3) | |
56 | and | |
57 | .BR mq_setattr (3). | |
c13182ef | 58 | A process can request asynchronous notification |
80a99f39 MK |
59 | of the arrival of a message on a previously empty queue using |
60 | .BR mq_notify (3). | |
61 | ||
62 | A message queue descriptor is a reference to an | |
c13182ef MK |
63 | .IR "open message queue description" |
64 | (cf. | |
80a99f39 | 65 | .BR open (2)). |
c13182ef | 66 | After a |
80a99f39 MK |
67 | .BR fork (2), |
68 | a child inherits copies of its parent's message queue descriptors, | |
c13182ef | 69 | and these descriptors refer to the same open message queue descriptions |
80a99f39 | 70 | as the corresponding descriptors in the parent. |
c13182ef | 71 | Corresponding descriptors in the two processes share the flags |
80a99f39 MK |
72 | .RI ( mq_flags ) |
73 | that are associated with the open message queue description. | |
74 | ||
c13182ef MK |
75 | Each message has an associated |
76 | .IR priority , | |
77 | and messages are always delivered to the receiving process | |
80a99f39 | 78 | highest priority first. |
c13182ef | 79 | Message priorities range from 0 (low) to |
80a99f39 MK |
80 | .I sysconf(_SC_MQ_PRIO_MAX)\ -\ 1 |
81 | (high). | |
82 | On Linux, | |
c13182ef | 83 | .I sysconf(_SC_MQ_PRIO_MAX) |
80a99f39 MK |
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. | |
8b215c30 MK |
87 | .PP |
88 | The remainder of this section describes some specific details | |
1ce284ec | 89 | of the Linux implementation of POSIX message queues. |
c4ac1bc4 MK |
90 | .SS Library interfaces and system calls |
91 | In most cases the | |
92 | .B mq_*() | |
93 | library interfaces listed above are implemented | |
94 | on top of underlying system calls of the same name. | |
95 | Deviations from this scheme are indicated in the following table: | |
96 | .in +0.25i | |
97 | .TS | |
98 | lB lB | |
99 | l l. | |
100 | Library interface System call | |
101 | mq_close(3) close(2) | |
102 | mq_getattr(3) mq_getsetattr(2) | |
103 | mq_open(3) mq_open(2) | |
104 | mq_receive(3) mq_timedreceive(2) | |
105 | mq_send(3) mq_timedsend(2) | |
106 | mq_setattr(3) mq_getsetattr(2) | |
107 | mq_timedreceive(3) mq_timedreceive(2) | |
108 | mq_timedsend(3) mq_timedsend(2) | |
109 | mq_unlink(3) mq_unlink(2) | |
110 | .TE | |
111 | .in -0.25i | |
80a99f39 MK |
112 | .SS Versions |
113 | POSIX message queues have been supported on Linux since kernel 2.6.6. | |
114 | Glibc support has been provided since version 2.3.4. | |
115 | .SS Kernel configuration | |
116 | Support for POSIX message queues is configurable via the | |
117 | .B CONFIG_POSIX_MQUEUE | |
c13182ef | 118 | kernel configuration option. |
80a99f39 MK |
119 | This option is enabled by default. |
120 | .SS Persistence | |
121 | POSIX message queues have kernel persistence: | |
122 | if not removed by | |
63f6a20a | 123 | .BR mq_unlink (3), |
80a99f39 MK |
124 | a message queue will exist until the system is shut down. |
125 | .SS Linking | |
126 | Programs using the POSIX message queue API must be compiled with | |
127 | .I cc \-lrt | |
128 | to link against the real-time library, | |
129 | .IR librt . | |
130 | .SS /proc interfaces | |
c13182ef | 131 | The following interfaces can be used to limit the amount of |
80a99f39 MK |
132 | kernel memory consumed by POSIX message queues: |
133 | .TP | |
134 | .I /proc/sys/fs/mqueue/msg_max | |
c13182ef | 135 | This file can be used to view and change the ceiling value for the |
80a99f39 MK |
136 | maximum number of messages in a queue. |
137 | This value acts as a ceiling on the | |
138 | .I attr->mq_maxmsg | |
139 | argument given to | |
140 | .BR mq_open (3). | |
141 | The default and minimum value for | |
142 | .I msg_max | |
143 | is 10; the upper limit is HARD_MAX: | |
c13182ef | 144 | .IR "(131072\ /\ sizeof(void\ *))" |
80a99f39 MK |
145 | (32768 on Linux/86). |
146 | This limit is ignored for privileged processes | |
147 | .RB ( CAP_SYS_RESOURCE ), | |
148 | but the HARD_MAX ceiling is nevertheless imposed. | |
149 | .TP | |
150 | .I /proc/sys/fs/mqueue/msgsize_max | |
c13182ef | 151 | This file can be used to view and change the ceiling on the |
80a99f39 MK |
152 | maximum message size. |
153 | This value acts as a ceiling on the | |
154 | .I attr->mq_msgsize | |
155 | argument given to | |
156 | .BR mq_open (3). | |
157 | The default and minimum value for | |
158 | .I msgsize_max | |
159 | is 8192 bytes; the upper limit is INT_MAX | |
160 | (2147483647 on Linux/86). | |
161 | This limit is ignored for privileged processes | |
162 | .RB ( CAP_SYS_RESOURCE ). | |
163 | .TP | |
164 | .I /proc/sys/fs/mqueue/queues_max | |
c13182ef | 165 | This file can be used to view and change the system-wide limit on the |
80a99f39 | 166 | number of message queues that can be created. |
c13182ef | 167 | Only privileged processes |
80a99f39 MK |
168 | .RB ( CAP_SYS_RESOURCE ) |
169 | can create new message queues once this limit has been reached. | |
170 | The default value for | |
171 | .I queues_max | |
172 | is 256; it can be changed to any value in the range 0 to INT_MAX. | |
173 | .SS Resource limit | |
174 | The | |
175 | .BR RLIMIT_MSGQUEUE | |
c13182ef MK |
176 | resource limit, which places a limit on the amount of space |
177 | that can be consumed by all of the message queues | |
178 | belonging to a process's real user ID, is described in | |
80a99f39 MK |
179 | .BR getrlimit (2). |
180 | .SS Mounting the message queue file system | |
181 | On Linux, message queues are created in a virtual file system. | |
c13182ef | 182 | (Other implementations may also provide such a feature, |
80a99f39 MK |
183 | but the details are likely to differ.) |
184 | This file system can be mounted using the following commands: | |
185 | .in +0.25i | |
186 | .nf | |
187 | ||
188 | $ mkdir /dev/mqueue | |
189 | $ mount -t mqueue none /dev/mqueue | |
190 | ||
191 | .fi | |
192 | .in -0.25i | |
193 | The sticky bit is automatically enabled on the mount directory. | |
194 | ||
c13182ef | 195 | After the file system has been mounted, the message queues on the system |
80a99f39 MK |
196 | can be viewed and manipulated using the commands usually used for files |
197 | (e.g., | |
198 | .BR ls (1) | |
199 | and | |
200 | .BR rm (1)). | |
201 | ||
c13182ef | 202 | The contents of each file in the directory consist of a single line |
80a99f39 MK |
203 | containing information about the queue: |
204 | .in +0.25i | |
205 | .nf | |
206 | ||
207 | $ ls /dev/mqueue/mymq | |
208 | QSIZE:129 NOTIFY:2 SIGNO:0 NOTIFY_PID:8260 | |
209 | $ mount -t mqueue none /dev/mqueue | |
210 | ||
211 | .fi | |
212 | .in -0.25i | |
213 | These fields are as follows: | |
214 | .TP | |
215 | .B | |
216 | QSIZE | |
217 | Number of bytes of data in all messages in the queue. | |
218 | .TP | |
219 | .B NOTIFY_PID | |
220 | If this is non-zero, then the process with this PID has used | |
221 | .BR mq_notify (3) | |
c13182ef | 222 | to register for asynchronous message notification, |
80a99f39 MK |
223 | and the remaining fields describe how notification occurs. |
224 | .TP | |
225 | .B NOTIFY | |
226 | Notification method: | |
c13182ef | 227 | 0 is |
80a99f39 MK |
228 | .BR SIGEV_SIGNAL ; |
229 | 1 is | |
4df883b9 | 230 | .BR SIGEV_NONE ; |
c13182ef | 231 | and |
80a99f39 MK |
232 | 2 is |
233 | .BR SIGEV_THREAD . | |
234 | .TP | |
235 | .B SIGNO | |
236 | Signal number to be used for | |
237 | .BR SIGEV_SIGNAL . | |
238 | .SS Polling message queue descriptors | |
239 | On Linux, a message queue descriptor is actually a file descriptor, | |
240 | and can be monitored using | |
241 | .BR select (2), | |
242 | .BR poll (2), | |
243 | or | |
2315114c | 244 | .BR epoll (7). |
80a99f39 MK |
245 | This is not portable. |
246 | .SH "CONFORMING TO" | |
247 | POSIX.1-2001. | |
248 | .SH NOTES | |
249 | System V message queues | |
250 | .RB ( msgget (2), | |
251 | .BR msgsnd (2), | |
252 | .BR msgrcv (2), | |
253 | etc.) are an older API for exchanging messages between processes. | |
254 | POSIX message queues provide a better designed interface than | |
c13182ef MK |
255 | System V message queues; |
256 | on the other hand POSIX message queues are less widely available | |
80a99f39 MK |
257 | (especially on older systems) than System V message queues. |
258 | .SH EXAMPLE | |
259 | An example of the use of various message queue functions is shown in | |
260 | .BR mq_notify (3). | |
261 | .SH "SEE ALSO" | |
262 | .BR getrlimit (2), | |
694ae673 | 263 | .BR mq_getsetattr (2), |
80a99f39 MK |
264 | .BR mq_close (3), |
265 | .BR mq_getattr (3), | |
266 | .BR mq_notify (3), | |
267 | .BR mq_open (3), | |
268 | .BR mq_receive (3), | |
269 | .BR mq_send (3), | |
270 | .BR mq_unlink (3), | |
271 | .BR poll (2), | |
272 | .BR select (2), | |
273 | .BR epoll (4) |