1 .\" Copyright (C) 2006 Michael Kerrisk <mtk.manpages@gmail.com>
3 .\" %%%LICENSE_START(VERBATIM)
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date. The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein. The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
25 .TH MQ_OPEN 3 2021-03-22 "Linux" "Linux Programmer's Manual"
27 mq_open \- open a message queue
30 .BR "#include <fcntl.h>" " /* For O_* constants */"
31 .BR "#include <sys/stat.h>" " /* For mode constants */"
32 .B #include <mqueue.h>
34 .BI "mqd_t mq_open(const char *" name ", int " oflag );
35 .BI "mqd_t mq_open(const char *" name ", int " oflag ", mode_t " mode ,
36 .BI " struct mq_attr *" attr );
39 Link with \fI\-lrt\fP.
42 creates a new POSIX message queue or opens an existing queue.
43 The queue is identified by
45 For details of the construction of
52 argument specifies flags that control the operation of the call.
53 (Definitions of the flags values can be obtained by including
55 Exactly one of the following must be specified in
59 Open the queue to receive messages only.
62 Open the queue to send messages only.
65 Open the queue to both send and receive messages.
67 Zero or more of the following flags can additionally be
72 .BR O_CLOEXEC " (since Linux 2.6.26)"
73 .\" commit 269f21344b23e552c21c9e2d7ca258479dcd7a0a
74 Set the close-on-exec flag for the message queue descriptor.
77 for a discussion of why this flag is useful.
80 Create the message queue if it does not exist.
81 The owner (user ID) of the message queue is set to the effective
82 user ID of the calling process.
83 The group ownership (group ID) is set to the effective group ID
84 of the calling process.
85 .\" In reality the filesystem IDs are used on Linux.
92 and a queue with the given
94 already exists, then fail with the error
98 Open the queue in nonblocking mode.
99 In circumstances where
103 would normally block, these functions instead fail with the error
110 then two additional arguments must be supplied.
113 argument specifies the permissions to be placed on the new queue,
116 (Symbolic definitions for the permissions bits can be obtained by including
118 The permissions settings are masked against the process umask.
124 specify the maximum number of messages and
125 the maximum size of messages that the queue will allow.
126 This structure is defined as follows:
131 long mq_flags; /* Flags (ignored for mq_open()) */
132 long mq_maxmsg; /* Max. # of messages on queue */
133 long mq_msgsize; /* Max. message size (bytes) */
134 long mq_curmsgs; /* # of messages currently in queue
135 (ignored for mq_open()) */
144 fields are employed when calling
146 the values in the remaining fields are ignored.
150 is NULL, then the queue is created with implementation-defined
154 files can be used to control these defaults; see
160 returns a message queue descriptor for use by other
161 message queue functions.
168 set to indicate the error.
172 The queue exists, but the caller does not have permission to
173 open it in the specified mode.
177 contained more than one slash.
178 .\" Note that this isn't consistent with the same case for sem_open()
187 but a queue with this
192 .\" glibc checks whether the name starts with a "/" and if not,
195 doesn't follow the format in
209 Both of these fields must be greater than zero.
210 In a process that is unprivileged (does not have the
214 must be less than or equal to the
218 must be less than or equal to the
221 In addition, even in a privileged process,
228 for details of these limits.)
231 The per-process limit on the number of open file
232 and message queue descriptors has been reached
233 (see the description of
243 The system-wide limit on the total number of open files
244 and message queues has been reached.
249 flag was not specified in
251 and no queue with this
257 was just "/" followed by no other characters.
258 .\" Note that this isn't consistent with the same case for sem_open()
264 Insufficient space for the creation of a new message queue.
265 This probably occurred because the
267 limit was encountered; see
270 For an explanation of the terms used in this section, see
278 Interface Attribute Value
281 T} Thread safety MT-Safe
287 POSIX.1-2001, POSIX.1-2008.
289 .SS C library/kernel differences
292 library function is implemented on top of a system call of the same name.
293 The library function performs the check that the
295 starts with a slash (/), giving the
297 error if it does not.
298 The kernel system call expects
300 to contain no preceding slash,
301 so the C library function passes
303 without the preceding slash (i.e.,
307 In kernels before 2.6.14,
308 the process umask was not applied to the permissions specified in