1 .\" Copyright (c) 2005 David Xu <davidxu@FreeBSD.org>
2 .\" All rights reserved.
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\" notice(s), this list of conditions and the following disclaimer as
9 .\" the first lines of this file unmodified other than the possible
10 .\" addition of one or more copyright notices.
11 .\" 2. Redistributions in binary form must reproduce the above copyright
12 .\" notice(s), this list of conditions and the following disclaimer in
13 .\" the documentation and/or other materials provided with the
16 .\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY
17 .\" EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 .\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE
20 .\" LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 .\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23 .\" BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24 .\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
25 .\" OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
26 .\" EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 .\" Portions of this text are reprinted and reproduced in electronic form
29 .\" from IEEE Std 1003.1, 2004 Edition, Standard for Information Technology --
30 .\" Portable Operating System Interface (POSIX), The Open Group Base
31 .\" Specifications Issue 6, Copyright (C) 2001-2004 by the Institute of
32 .\" Electrical and Electronics Engineers, Inc and The Open Group. In the
33 .\" event of any discrepancy between this version and the original IEEE and
34 .\" The Open Group Standard, the original IEEE and The Open Group Standard is
35 .\" the referee document. The original Standard can be obtained online at
36 .\" http://www.opengroup.org/unix/online.html.
38 .Dd September 26, 2023
43 .Nd "open a message queue (REALTIME)"
49 .Fn mq_open "const char *name" "int oflag" "..."
53 system call establishes the connection between a process and a message queue
54 with a message queue descriptor.
55 It creates an open message queue
56 description that refers to the message queue, and a message queue descriptor
57 that refers to that open message queue description.
59 descriptor is used by other functions to refer to that message queue.
62 argument points to a string naming a message queue.
65 argument should conform to the construction rules for a pathname.
68 should begin with a slash character.
71 with the same value of
73 refers to the same message queue object, as long as that name has not been
77 argument is not the name of an existing message queue and creation is not
80 will fail and return an error.
84 argument requests the desired receive and/or send access to the message
86 The requested access permission to receive messages or send messages
87 would be granted if the calling process would be granted read or write access,
88 respectively, to an equivalently protected file.
92 is the bitwise-inclusive OR of values from the following list.
93 Applications should specify exactly one of the first three values (access
94 modes) below in the value of
96 .Bl -tag -width ".Dv O_NONBLOCK"
98 Open the message queue for receiving messages.
99 The process can use the
100 returned message queue descriptor with
104 A message queue may be open multiple times in the same or different processes
105 for receiving messages.
107 Open the queue for sending messages.
108 The process can use the returned
109 message queue descriptor with
113 A message queue may be open multiple times in the same or different processes
114 for sending messages.
116 Open the queue for both receiving and sending messages.
118 any of the functions allowed for
122 A message queue may be open multiple times in the same or different processes
123 for sending messages.
126 Any combination of the remaining flags may be specified in the value of
128 .Bl -tag -width ".Dv O_NONBLOCK"
130 Create a message queue.
131 It requires two additional arguments:
137 which is a pointer to an
142 has already been used to create a message queue that still exists, then
143 this flag has no effect, except as noted under
145 Otherwise, a message queue will be created without any messages
147 The user ID of the message queue will be set to the effective user ID
148 of the process, and the group ID of the message queue will be set to the
149 effective group ID of the process.
150 The permission bits of the message queue
151 will be set to the value of the
153 argument, except those set in the file mode creation mask of the process.
156 other than the file permission bits are specified, the effect is
162 the message queue is created with implementation-defined default message
166 and the calling process has the
167 appropriate privilege on name, the message queue
171 attributes will be set to the values of the corresponding members in the
173 structure referred to by
179 but the calling process does not have the appropriate privilege
182 function will fail and return an error without creating the message queue.
190 will fail if the message queue name exists.
192 Determines whether an
196 waits for resources or messages that are not currently available, or fails
210 system call does not add or remove messages from the queue.
213 implements message queue based on file descriptor.
215 is inherited by child after
217 The descriptor is closed in a new image after
223 system calls are supported for message queue descriptor.
227 man page for instructions on loading the module or compiling the service into
230 The number of queues available, the maximum number of messages per queue
231 and the maximum message size are tunable
234 Their defaults are as follows.
235 .Bl -column kern.mqueue.maxmsgsize integerxxx
236 .It Sy "Name Type Default"
237 .It "kern.mqueue.maxmq integer 100"
238 .It "kern.mqueue.maxmsgsize integer 16384"
239 .It "kern.mqueue.maxmsg integer 100"
242 Upon successful completion, the function returns a message queue
243 descriptor; otherwise, the function returns
244 .Po Vt mqd_t Pc Ns \-1
245 and sets the global variable
247 to indicate the error.
255 The message queue exists and the permissions specified by
257 are denied, or the message queue does not exist and permission to create the
258 message queue is denied.
263 are set and the named message queue already exists.
267 function was interrupted by a signal.
271 function is not supported for the given name.
284 was less than or equal to zero.
286 Too many message queue descriptors or file descriptors are currently in use
288 .It Bq Er ENAMETOOLONG
293 or a pathname component
297 Too many message queues are currently open in the system.
300 is not set and the named message queue does not exist.
302 There is insufficient space for the creation of the new message queue.
311 .Xr mq_timedreceive 3 ,
317 system call conforms to
320 Support for POSIX message queues first appeared in
323 This implementation places strict requirements on the value of
325 it must begin with a slash
327 and contain no other slash characters.
333 arguments are variadic and may result in different calling conventions
334 than might otherwise be expected.
336 Portions of this text are reprinted and reproduced in electronic form
337 from IEEE Std 1003.1, 2004 Edition, Standard for Information Technology --
338 Portable Operating System Interface (POSIX), The Open Group Base
339 Specifications Issue 6, Copyright (C) 2001-2004 by the Institute of
340 Electrical and Electronics Engineers, Inc and The Open Group. In the
341 event of any discrepancy between this version and the original IEEE and
342 The Open Group Standard, the original IEEE and The Open Group Standard is
343 the referee document. The original Standard can be obtained online at
344 http://www.opengroup.org/unix/online.html.