1 .\" Copyright (C) 2006 Michael Kerrisk <mtk.manpages@gmail.com>
3 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
5 .TH MQ_OPEN 3 2021-03-22 "Linux" "Linux Programmer's Manual"
7 mq_open \- open a message queue
10 .RI ( librt ", " \-lrt )
13 .BR "#include <fcntl.h>" " /* For O_* constants */"
14 .BR "#include <sys/stat.h>" " /* For mode constants */"
15 .B #include <mqueue.h>
17 .BI "mqd_t mq_open(const char *" name ", int " oflag );
18 .BI "mqd_t mq_open(const char *" name ", int " oflag ", mode_t " mode ,
19 .BI " struct mq_attr *" attr );
23 creates a new POSIX message queue or opens an existing queue.
24 The queue is identified by
26 For details of the construction of
33 argument specifies flags that control the operation of the call.
34 (Definitions of the flags values can be obtained by including
36 Exactly one of the following must be specified in
40 Open the queue to receive messages only.
43 Open the queue to send messages only.
46 Open the queue to both send and receive messages.
48 Zero or more of the following flags can additionally be
53 .BR O_CLOEXEC " (since Linux 2.6.26)"
54 .\" commit 269f21344b23e552c21c9e2d7ca258479dcd7a0a
55 Set the close-on-exec flag for the message queue descriptor.
58 for a discussion of why this flag is useful.
61 Create the message queue if it does not exist.
62 The owner (user ID) of the message queue is set to the effective
63 user ID of the calling process.
64 The group ownership (group ID) is set to the effective group ID
65 of the calling process.
66 .\" In reality the filesystem IDs are used on Linux.
73 and a queue with the given
75 already exists, then fail with the error
79 Open the queue in nonblocking mode.
80 In circumstances where
84 would normally block, these functions instead fail with the error
91 then two additional arguments must be supplied.
94 argument specifies the permissions to be placed on the new queue,
97 (Symbolic definitions for the permissions bits can be obtained by including
99 The permissions settings are masked against the process umask.
105 specify the maximum number of messages and
106 the maximum size of messages that the queue will allow.
107 This structure is defined as follows:
112 long mq_flags; /* Flags (ignored for mq_open()) */
113 long mq_maxmsg; /* Max. # of messages on queue */
114 long mq_msgsize; /* Max. message size (bytes) */
115 long mq_curmsgs; /* # of messages currently in queue
116 (ignored for mq_open()) */
125 fields are employed when calling
127 the values in the remaining fields are ignored.
131 is NULL, then the queue is created with implementation-defined
135 files can be used to control these defaults; see
141 returns a message queue descriptor for use by other
142 message queue functions.
149 set to indicate the error.
153 The queue exists, but the caller does not have permission to
154 open it in the specified mode.
158 contained more than one slash.
159 .\" Note that this isn't consistent with the same case for sem_open()
168 but a queue with this
173 .\" glibc checks whether the name starts with a "/" and if not,
176 doesn't follow the format in
190 Both of these fields must be greater than zero.
191 In a process that is unprivileged (does not have the
195 must be less than or equal to the
199 must be less than or equal to the
202 In addition, even in a privileged process,
209 for details of these limits.)
212 The per-process limit on the number of open file
213 and message queue descriptors has been reached
214 (see the description of
224 The system-wide limit on the total number of open files
225 and message queues has been reached.
230 flag was not specified in
232 and no queue with this
238 was just "/" followed by no other characters.
239 .\" Note that this isn't consistent with the same case for sem_open()
245 Insufficient space for the creation of a new message queue.
246 This probably occurred because the
248 limit was encountered; see
251 For an explanation of the terms used in this section, see
259 Interface Attribute Value
262 T} Thread safety MT-Safe
268 POSIX.1-2001, POSIX.1-2008.
270 .SS C library/kernel differences
273 library function is implemented on top of a system call of the same name.
274 The library function performs the check that the
276 starts with a slash (/), giving the
278 error if it does not.
279 The kernel system call expects
281 to contain no preceding slash,
282 so the C library function passes
284 without the preceding slash (i.e.,
288 In kernels before 2.6.14,
289 the process umask was not applied to the permissions specified in