2 .\" Copyright (C) 2006 Michael Kerrisk <mtk.manpages@gmail.com>
4 .\" %%%LICENSE_START(VERBATIM)
5 .\" Permission is granted to make and distribute verbatim copies of this
6 .\" manual provided the copyright notice and this permission notice are
7 .\" preserved on all copies.
9 .\" Permission is granted to copy and distribute modified versions of this
10 .\" manual under the conditions for verbatim copying, provided that the
11 .\" entire resulting derived work is distributed under the terms of a
12 .\" permission notice identical to this one.
14 .\" Since the Linux kernel and libraries are constantly changing, this
15 .\" manual page may be incorrect or out-of-date. The author(s) assume no
16 .\" responsibility for errors or omissions, or for damages resulting from
17 .\" the use of the information contained herein. The author(s) may not
18 .\" have taken the same level of care in the production of this manual,
19 .\" which is licensed free of charge, as they might when working
22 .\" Formatted or processed versions of this manual, if unaccompanied by
23 .\" the source, must acknowledge the copyright and authors of this work.
26 .TH MQ_OPEN 3 2017-09-15 "Linux" "Linux Programmer's Manual"
28 mq_open \- open a message queue
31 .BR "#include <fcntl.h>" " /* For O_* constants */"
32 .BR "#include <sys/stat.h>" " /* For mode constants */"
33 .B #include <mqueue.h>
35 .BI "mqd_t mq_open(const char *" name ", int " oflag );
36 .BI "mqd_t mq_open(const char *" name ", int " oflag ", mode_t " mode ,
37 .BI " struct mq_attr *" attr );
40 Link with \fI\-lrt\fP.
43 creates a new POSIX message queue or opens an existing queue.
44 The queue is identified by
46 For details of the construction of
53 argument specifies flags that control the operation of the call.
54 (Definitions of the flags values can be obtained by including
56 Exactly one of the following must be specified in
60 Open the queue to receive messages only.
63 Open the queue to send messages only.
66 Open the queue to both send and receive messages.
68 Zero or more of the following flags can additionally be
73 .BR O_CLOEXEC " (since Linux 2.6.26)"
74 .\" commit 269f21344b23e552c21c9e2d7ca258479dcd7a0a
75 Set the close-on-exec flag for the message queue descriptor.
78 for a discussion of why this flag is useful.
81 Create the message queue if it does not exist.
82 The owner (user ID) of the message queue is set to the effective
83 user ID of the calling process.
84 The group ownership (group ID) is set to the effective group ID
85 of the calling process.
86 .\" In reality the filesystem IDs are used on Linux.
93 and a queue with the given
95 already exists, then fail with the error
99 Open the queue in nonblocking mode.
100 In circumstances where
104 would normally block, these functions instead fail with the error
111 then two additional arguments must be supplied.
114 argument specifies the permissions to be placed on the new queue,
117 (Symbolic definitions for the permissions bits can be obtained by including
119 The permissions settings are masked against the process umask.
125 specify the maximum number of messages and
126 the maximum size of messages that the queue will allow.
127 This structure is defined as follows:
133 long mq_flags; /* Flags (ignored for mq_open()) */
134 long mq_maxmsg; /* Max. # of messages on queue */
135 long mq_msgsize; /* Max. message size (bytes) */
136 long mq_curmsgs; /* # of messages currently in queue
137 (ignored for mq_open()) */
146 fields are employed when calling
148 the values in the remaining fields are ignored.
152 is NULL, then the queue is created with implementation-defined
156 files can be used to control these defaults; see
162 returns a message queue descriptor for use by other
163 message queue functions.
170 set to indicate the error.
174 The queue exists, but the caller does not have permission to
175 open it in the specified mode.
179 contained more than one slash.
180 .\" Note that this isn't consistent with the same case for sem_open()
189 but a queue with this
194 .\" glibc checks whether the name starts with a "/" and if not,
197 doesn't follow the format in
211 Both of these fields must be greater than zero.
212 In a process that is unprivileged (does not have the
216 must be less than or equal to the
220 must be less than or equal to the
223 In addition, even in a privileged process,
230 for details of these limits.)
233 The per-process limit on the number of open file
234 and message queue descriptors has been reached
235 (see the description of
245 The system-wide limit on the total number of open files
246 and message queues has been reached.
251 flag was not specified in
253 and no queue with this
259 was just "/" followed by no other characters.
260 .\" Note that this isn't consistent with the same case for sem_open()
266 Insufficient space for the creation of a new message queue.
267 This probably occurred because the
269 limit was encountered; see
272 For an explanation of the terms used in this section, see
278 Interface Attribute Value
281 T} Thread safety MT-Safe
284 POSIX.1-2001, POSIX.1-2008.
286 .SS C library/kernel differences
289 library function is implemented on top of a system call of the same name.
290 The library function performs the check that the
292 starts with a slash (/), giving the
294 error if it does not.
295 The kernel system call expects
297 to contain no preceding slash,
298 so the C library function passes
300 without the preceding slash (i.e.,
304 In kernels before 2.6.14,
305 the process umask was not applied to the permissions specified in