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