MQ_OPEN(3POSIX)
π PROLOG π
okay bestie, real talk before we get into it: this manual page is part of the POSIX Programmer's Manual. The Linux implementation of this interface may differ (so go peek at the corresponding Linux manual page for the tea on Linux behavior), or the interface might not even be implemented on Linux at all. π
πΈ NAME πΈ
mq_open β open a message queue (REALTIME) β¨
π SYNOPSIS π
#include <mqueue.h>
mqd_t mq_open(const char *name, int oflag, ...);
π¦ DESCRIPTION π¦
so what does mq_open() actually do? It establishes the connection between a process and a message queue using a message queue descriptor. π« It creates an open message queue description that refers to the message queue, plus a message queue descriptor that refers to that open message queue description. Other functions use that descriptor to refer to the message queue. Main character energy tbh.
The name argument points to a string naming a message queue. It is unspecified whether the name appears in the file system and is visible to other functions that take pathnames as arguments. The name argument conforms to the construction rules for a pathname, except that the interpretation of <slash> characters other than the leading <slash> character in name is implementation-defined, and the length limits for the name argument are implementation-defined and need not be the same as the pathname limits {PATH_MAX} and {NAME_MAX}. no cap.
If name begins with the <slash> character, then processes calling mq_open() with the same value of name shall refer to the same message queue object β as long as that name has not been removed. π«Ά If name does not begin with the <slash> character, the effect is implementation-defined. And if the name argument is not the name of an existing message queue and creation is not requested, mq_open() shall fail and return an error. π
A message queue descriptor may be implemented using a file descriptor β in which case applications can open up to at least {OPEN_MAX} file and message queues. slay.
The oflag argument requests the desired receive and/or send access to the message queue. The requested access permission to receive messages or send messages shall be granted if the calling process would be granted read or write access, respectively, to an equivalently protected file. β¨
The value of oflag is the bitwise-inclusive OR of values from the following list. Applications shall specify exactly one of the first three values (the access modes) below in the value of oflag:
O_RDONLYβ open the message queue for receiving messages. The process can use the returned message queue descriptor withmq_receive(), but notmq_send(). A message queue may be open multiple times in the same or different processes for receiving messages. πO_WRONLYβ open the queue for sending messages. The process can use the returned message queue descriptor withmq_send()but notmq_receive(). A message queue may be open multiple times in the same or different processes for sending messages. π€O_RDWRβ open the queue for both receiving and sending messages. The process can use any of the functions allowed forO_RDONLYandO_WRONLY. A message queue may be open multiple times in the same or different processes for sending messages. π
Any combination of the remaining flags may be specified in the value of oflag:
O_CREATβ create a message queue. It requires two additional arguments:mode, which shall be of typemode_t, andattr, which shall be a pointer to anmq_attrstructure. If the pathnamenamehas already been used to create a message queue that still exists, then this flag shall have no effect, except as noted underO_EXCL. Otherwise, a message queue shall be created without any messages in it. The user ID of the message queue shall be set to the effective user ID of the process. The group ID of the message queue shall be set to the effective group ID of the process; however, if thenameargument is visible in the file system, the group ID may be set to the group ID of the containing directory. When bits inmodeother than the file permission bits are specified, the effect is unspecified. IfattrisNULL, the message queue shall be created with implementation-defined default message queue attributes. Ifattris non-NULLand the calling process has appropriate privileges onname, the message queuemq_maxmsgandmq_msgsizeattributes shall be set to the values of the corresponding members in themq_attrstructure referred to byattr. The values of themq_flagsandmq_curmsgsmembers of themq_attrstructure shall be ignored. Ifattris non-NULL, but the calling process does not have appropriate privileges onname, themq_open()function shall fail and return an error without creating the message queue. π€O_EXCLβ ifO_EXCLandO_CREATare set,mq_open()shall fail if the message queue name exists. The check for the existence of the message queue and the creation of the message queue if it does not exist shall be atomic with respect to other threads executingmq_open()naming the samenamewithO_EXCLandO_CREATset. π₯ IfO_EXCLis set andO_CREATis not set, the result is undefined. πO_NONBLOCKβ determines whether anmq_send()ormq_receive()waits for resources or messages that are not currently available, or fails witherrnoset to[EAGAIN]; seemq_send()andmq_receive()for details. β³
The mq_open() function does not add or remove messages from the queue. just so we're clear π«Ά
π RETURN VALUE π
Upon successful completion, the function shall return a message queue descriptor; otherwise, the function shall return (mqd_t)-1 and set errno to indicate the error. π
π ERRORS π
The mq_open() function shall fail if:
EACCESβ the message queue exists and the permissions specified byoflagare denied, or the message queue does not exist and permission to create the message queue is denied. π«EEXISTβO_CREATandO_EXCLare set and the named message queue already exists. (it's giving "already taken") πEINTRβ themq_open()function was interrupted by a signal. π΅EINVALβ themq_open()function is not supported for the givenname.EINVALβO_CREATwas specified inoflag, the value ofattris notNULL, and eithermq_maxmsgormq_msgsizewas less than or equal to zero. πEMFILEβ too many message queue descriptors or file descriptors are currently in use by this process. π₯΅ENFILEβ too many message queues are currently open in the system.ENOENTβO_CREATis not set and the named message queue does not exist. π»ENOSPCβ there is insufficient space for the creation of the new message queue. πͺ«
If any of the following conditions occur, the mq_open() function may return (mqd_t)-1 and set errno to the corresponding value:
ENAMETOOLONGβ the length of thenameargument exceeds{_POSIX_PATH_MAX}on systems that do not support the XSI option or exceeds{_XOPEN_PATH_MAX}on XSI systems, or has a pathname component that is longer than{_POSIX_NAME_MAX}on systems that do not support the XSI option or longer than{_XOPEN_NAME_MAX}on XSI systems. π
The following sections are informative. (translation: they're the bonus content, not the rules π)
π§ EXAMPLES π§
None.
π APPLICATION USAGE π
None.
π RATIONALE π
None.
β FUTURE DIRECTIONS β
A future version might require the mq_open() and mq_unlink() functions to have semantics similar to normal file system operations. π
π SEE ALSO π
mq_close(), mq_getattr(), mq_receive(), mq_send(), mq_setattr(), mq_unlink(), msgctl(), msgget(), msgrcv(), msgsnd()
The Base Definitions volume of POSIX.1β2017, <mqueue.h> πΈ
π COPYRIGHT π
Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html . π
Any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. To report such errors, see https://www.kernel.org/doc/man-pages/reporting_bugs.html . π
and that's the whole vibe bestie π this one's brought to you by IEEE/The Open Group, 2017 β MQ_OPEN(3POSIX), POSIX Programmer's Manual. go forth and open your queues responsibly π«Άβ¨
π¦ where this page comes from
- debian bookworm: manpages-posix-dev 2017a-2 Β· Other
- debian trixie: manpages-posix-dev 2017a-2 Β· Other
- ubuntu jammy: manpages-posix-dev 2017a-2 Β· Other
- ubuntu noble: manpages-posix-dev 2017a-2 Β· Other
- ubuntu resolute: manpages-posix-dev 2017a-2build1 Β· Other
- ubuntu stonking: manpages-posix-dev 2017a-2.1 Β· Other
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms