mq_overview(7)
๐ mq_overview โ the tea on POSIX message queues ๐
okay bestie, welcome to mq_overview(7), a page from the Miscellaneous Information Manual (section 7, the misc girlies section ๐
). This is the glow-up guide to POSIX message queues. Sit down, hydrate, let's go.
๐ธ NAME
mq_overview โ overview of POSIX message queues
โจ DESCRIPTION
POSIX message queues let processes swap data in the form of messages. And no, it's not the same API as the one from System V message queues (msgget(2), msgsnd(2), msgrcv(2), etc.) โ but fr fr, it does basically the same job.
You create and open queues with mq_open(3). That call hands you back a message queue descriptor (mqd_t), and that descriptor is your little golden ticket โ you use it in all the later calls to refer to that open queue. Every message queue has a name shaped like /somename, meaning: a null-terminated string of up to NAME_MAX (i.e. 255) characters, starting with a slash, then one or more characters, and none of those characters are slashes. Two processes can work on the same queue by passing that same name to mq_open(3). iconic.
Messages travel to and from a queue via mq_send(3) and mq_receive(3). When a process is done with a queue, it closes it with mq_close(3), and when the queue is truly no longer needed, it can be deleted with mq_unlink(3) (the breakup). Queue attributes can be read and โ in some cases โ modified using mq_getattr(3) and mq_setattr(3). And if you want a heads-up when a message lands on a previously empty queue, a process can request asynchronous notification using mq_notify(3) ๐.
A message queue descriptor is a reference to an open message queue description (see open(2)). After a fork(2), the child inherits copies of its parent's message queue descriptors, and those descriptors refer to the same open message queue descriptions as the corresponding ones in the parent. Corresponding message queue descriptors in the two processes share the flags (mq_flags) associated with the open message queue description. sharing is caring ๐ซถ
Every message has a priority attached, and messages are always delivered to the receiving process highest priority first. Priorities run from 0 (low) up to sysconf(_SC_MQ_PRIO_MAX) - 1 (high). On Linux, sysconf(_SC_MQ_PRIO_MAX) returns 32768, but POSIX.1 only requires that an implementation support at least priorities in the range 0 to 31 โ some implementations only give you that range. so if you're on Linux, you're eating good.
The rest of this section is all about the specific details of the Linux implementation of POSIX message queues. ๐
๐ง Library interfaces and system calls
In most cases, the mq_*() library interfaces listed above are actually sitting on top of underlying system calls with the same name. The deviations from that pattern are listed here:
mq_close(3)โclose(2)mq_getattr(3)โmq_getsetattr(2)mq_notify(3)โmq_notify(2)mq_open(3)โmq_open(2)mq_receive(3)โmq_timedreceive(2)mq_send(3)โmq_timedsend(2)mq_setattr(3)โmq_getsetattr(2)mq_timedreceive(3)โmq_timedreceive(2)mq_timedsend(3)โmq_timedsend(2)mq_unlink(3)โmq_unlink(2)
๐ฆ Versions
POSIX message queues have been supported since Linux 2.6.6. glibc support has been provided since glibc 2.3.4. vintage but still in her prime โจ
๐ Kernel configuration
Support for POSIX message queues is configurable via the CONFIG_POSIX_MQUEUE kernel configuration option. This option is enabled by default.
๐ Persistence
POSIX message queues have kernel persistence: if they're not removed by mq_unlink(3), a message queue will exist until the system is shut down. she's committed. she's staying. no cap.
๐ธ Linking
Programs using the POSIX message queue API must be compiled with cc -lrt to link against the real-time library, librt. don't forget it or the linker will simply not let you live ๐
๐ /proc interfaces
These interfaces let you limit how much kernel memory POSIX message queues can gobble up, and set the default attributes for new message queues:
/proc/sys/fs/mqueue/msg_default (since Linux 3.5)
This file defines the value used for a new queue's mq_maxmsg setting when the queue is created with a call to mq_open(3) where attr is specified as NULL. The default value for this file is 10. The minimum and maximum are as for /proc/sys/fs/mqueue/msg_max. A new queue's default mq_maxmsg value will be the smaller of msg_default and msg_max. Before Linux 2.6.28, the default mq_maxmsg was 10; from Linux 2.6.28 to Linux 3.4, the default was the value defined for the msg_max limit. history lesson, bestie ๐
/proc/sys/fs/mqueue/msg_max
This file can be used to view and change the ceiling value for the maximum number of messages in a queue. This value acts as a ceiling on the attr->mq_maxmsg argument given to mq_open(3). The default value for msg_max is 10. The minimum value is 1 (10 before Linux 2.6.28). The upper limit is HARD_MSGMAX. The msg_max limit is ignored for privileged processes (CAP_SYS_RESOURCE), but the HARD_MSGMAX ceiling is nevertheless imposed.
The definition of HARD_MSGMAX has changed across kernel versions, and yes we're listing all of them:
- Up to Linux 2.6.32:
131072 / sizeof(void *) - Linux 2.6.33 to Linux 3.4:
(32768 * sizeof(void *) / 4) - Since Linux 3.5:
65,536
/proc/sys/fs/mqueue/msgsize_default (since Linux 3.5)
This file defines the value used for a new queue's mq_msgsize setting when the queue is created with a call to mq_open(3) where attr is specified as NULL. The default value for this file is 8192 (bytes). The minimum and maximum are as for /proc/sys/fs/mqueue/msgsize_max. If msgsize_default exceeds msgsize_max, a new queue's default mq_msgsize value is capped to the msgsize_max limit. Before Linux 2.6.28, the default mq_msgsize was 8192; from Linux 2.6.28 to Linux 3.4, the default was the value defined for the msgsize_max limit.
/proc/sys/fs/mqueue/msgsize_max
This file can be used to view and change the ceiling on the maximum message size. This value acts as a ceiling on the attr->mq_msgsize argument given to mq_open(3). The default value for msgsize_max is 8192 bytes. The minimum value is 128 (8192 before Linux 2.6.28). The upper limit for msgsize_max has varied across kernel versions:
- Before Linux 2.6.28, the upper limit is
INT_MAX. - From Linux 2.6.28 to Linux 3.4, the limit is
1,048,576. - Since Linux 3.5, the limit is
16,777,216(HARD_MSGSIZEMAX).
The msgsize_max limit is ignored for privileged process (CAP_SYS_RESOURCE), but, since Linux 3.5, the HARD_MSGSIZEMAX ceiling is enforced for privileged processes.
/proc/sys/fs/mqueue/queues_max
This file can be used to view and change the system-wide limit on the number of message queues that can be created. The default value for queues_max is 256. No ceiling is imposed on the queues_max limit; privileged processes (CAP_SYS_RESOURCE) can exceed the limit (but see BUGS). drama incoming, keep reading ๐
๐ Resource limit
The RLIMIT_MSGQUEUE resource limit places a limit on the amount of space that can be consumed by all of the message queues belonging to a process's real user ID โ and it's described over in getrlimit(2).
๐ง Mounting the message queue filesystem
On Linux, message queues are created in a virtual filesystem. (Other implementations may also provide such a feature, but the details are likely to differ.) This filesystem can be mounted โ by the superuser โ using the following commands:
# mkdir /dev/mqueue
# mount -t mqueue none /dev/mqueue
The sticky bit is automatically enabled on the mount directory. ๐
Once the filesystem is mounted, the message queues on the system can be viewed and manipulated using the commands you'd normally use for files (e.g., ls(1) and rm(1)).
The contents of each file in the directory consist of a single line containing information about the queue:
$ cat /dev/mqueue/mymq
QSIZE:129 NOTIFY:2 SIGNO:0 NOTIFY_PID:8260
These fields are as follows:
QSIZEโ Number of bytes of data in all messages in the queue (but see BUGS).NOTIFY_PIDโ If this is nonzero, then the process with this PID has usedmq_notify(3)to register for asynchronous message notification, and the remaining fields describe how notification occurs.NOTIFYโ Notification method:0isSIGEV_SIGNAL;1isSIGEV_NONE; and2isSIGEV_THREAD.SIGNOโ Signal number to be used forSIGEV_SIGNAL.
๐ซ Linux implementation of message queue descriptors
On Linux, a message queue descriptor is actually a file descriptor. (POSIX does not require such an implementation.) This means a message queue descriptor can be monitored using select(2), poll(2), or epoll(7). This is not portable though, so don't get too comfy ๐ซ
The close-on-exec flag (see open(2)) is automatically set on the file descriptor returned by mq_open(2).
๐ IPC namespaces
For a discussion of the interaction of POSIX message queue objects and IPC namespaces, see ipc_namespaces(7).
๐ NOTES
System V message queues (msgget(2), msgsnd(2), msgrcv(2), etc.) are an older API for exchanging messages between processes. POSIX message queues provide a better designed interface than System V message queues; on the other hand, POSIX message queues are less widely available (especially on older systems) than System V message queues. trade-offs, bestie, it's giving โจbalanceโจ
Linux does not currently (Linux 2.6.26) support the use of access control lists (ACLs) for POSIX message queues.
๐ BUGS
Since Linux 3.5 to Linux 3.14, the kernel imposed a ceiling of 1024 (HARD_QUEUESMAX) on the value to which the queues_max limit could be raised, and the ceiling was enforced even for privileged processes. This ceiling value was removed in Linux 3.14, and patches to stable Linux 3.5.x to Linux 3.13.x also removed the ceiling.
As originally implemented (and documented), the QSIZE field displayed the total number of (user-supplied) bytes in all messages in the message queue. Some changes in Linux 3.5 inadvertently changed the behavior, so that this field also included a count of kernel overhead bytes used to store the messages in the queue. This behavioral regression was rectified in Linux 4.2 (and earlier stable kernel series), so that the count once more included just the bytes of user data in messages in the queue. redemption arc complete ๐๏ธ
๐ง EXAMPLES
An example of the use of various message queue functions is shown in mq_notify(3). go read it, it's cute.
๐ SEE ALSO
getrlimit(2), mq_getsetattr(2), poll(2), select(2), mq_close(3), mq_getattr(3), mq_notify(3), mq_open(3), mq_receive(3), mq_send(3), mq_unlink(3), epoll(7), namespaces(7)
and that's the whole page, bestie ๐ this one's from Linux man-pages 6.20, dated 2026-02-08 โ so you know it's fresh. now go mq_open(3) something and slay ๐โจ
๐ฆ where this page comes from
- arch rolling: man-pages 6.20-1 ยท BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages 6.20
- ๐ the page's license: Linux-man-pages-copyleft
- Copyright 2006, Michael Kerrisk <mtk.manpages@gmail.com>
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms