{
    "content": [
        {
            "type": "text",
            "text": "# mq_overview(7) (man)\n\n**Summary:** mqoverview - overview of POSIX message queues\n\n## Examples\n\n- `An example of the use of various message queue functions is shown in mqnotify(3).`\n\n## See Also\n\n- getrlimit(2)\n- mqgetsetattr(2)\n- poll(2)\n- select(2)\n- mqclose(3)\n- mqgetattr(3)\n- mqnotify(3)\n- mqopen(3)\n- mqreceive(3)\n- mqsend(3)\n- mqunlink(3)\n- epoll(7)\n- namespaces(7)\n\n## Section Outline\n\n- **NAME** (2 lines)\n- **DESCRIPTION** (34 lines) — 10 subsections\n  - Library interfaces and system calls (16 lines)\n  - Versions (3 lines)\n  - Kernel configuration (3 lines)\n  - Persistence (3 lines)\n  - Linking (3 lines)\n  - /proc interfaces (58 lines)\n  - Resource limit (4 lines)\n  - Mounting the message queue filesystem (31 lines)\n  - Linux implementation of message queue descriptors (7 lines)\n  - IPC namespaces (3 lines)\n- **NOTES** (8 lines)\n- **BUGS** (12 lines)\n- **EXAMPLES** (2 lines)\n- **SEE ALSO** (3 lines)\n- **COLOPHON** (7 lines)\n\n## Full Content\n\n### NAME\n\nmqoverview - overview of POSIX message queues\n\n### DESCRIPTION\n\nPOSIX  message  queues allow processes to exchange data in the form of messages.  This API is\ndistinct from that provided by System V  message  queues  (msgget(2),  msgsnd(2),  msgrcv(2),\netc.), but provides similar functionality.\n\nMessage queues are created and opened using mqopen(3); this function returns a message queue\ndescriptor (mqdt), which is used to refer to the open message queue in  later  calls.   Each\nmessage  queue  is  identified  by  a  name of the form /somename; that is, a null-terminated\nstring of up to NAMEMAX (i.e., 255) characters consisting of an initial slash,  followed  by\none  or  more  characters,  none of which are slashes.  Two processes can operate on the same\nqueue by passing the same name to mqopen(3).\n\nMessages are transferred to and from a queue using  mqsend(3)  and  mqreceive(3).   When  a\nprocess  has  finished using the queue, it closes it using mqclose(3), and when the queue is\nno longer required, it can be deleted using mqunlink(3).  Queue attributes can be  retrieved\nand  (in  some  cases) modified using mqgetattr(3) and mqsetattr(3).  A process can request\nasynchronous notification of the arrival of a message  on  a  previously  empty  queue  using\nmqnotify(3).\n\nA message queue descriptor is a reference to an open message queue description (see open(2)).\nAfter a fork(2), a child inherits copies of its parent's message queue descriptors, and these\ndescriptors  refer  to  the same open message queue descriptions as the corresponding message\nqueue descriptors in the parent.  Corresponding message queue descriptors  in  the  two  pro‐\ncesses  share  the  flags (mqflags) that are associated with the open message queue descrip‐\ntion.\n\nEach message has an associated priority, and messages are always delivered to  the  receiving\nprocess   highest   priority   first.    Message   priorities   range   from   0   (low)   to\nsysconf(SCMQPRIOMAX) - 1 (high).  On Linux, sysconf(SCMQPRIOMAX) returns  32768,  but\nPOSIX.1  requires  only  that an implementation support at least priorities in the range 0 to\n31; some implementations provide only this range.\n\nThe remainder of this section describes some specific details of the Linux implementation  of\nPOSIX message queues.\n\n#### Library interfaces and system calls\n\nIn most cases the mq*() library interfaces listed above are implemented on top of underlying\nsystem calls of the same name.  Deviations from this scheme are indicated  in  the  following\ntable:\n\nLibrary interface    System call\nmqclose(3)          close(2)\nmqgetattr(3)        mqgetsetattr(2)\nmqnotify(3)         mqnotify(2)\nmqopen(3)           mqopen(2)\nmqreceive(3)        mqtimedreceive(2)\nmqsend(3)           mqtimedsend(2)\nmqsetattr(3)        mqgetsetattr(2)\nmqtimedreceive(3)   mqtimedreceive(2)\nmqtimedsend(3)      mqtimedsend(2)\nmqunlink(3)         mqunlink(2)\n\n#### Versions\n\nPOSIX message queues have been supported on Linux since kernel 2.6.6.  Glibc support has been\nprovided since version 2.3.4.\n\n#### Kernel configuration\n\nSupport for POSIX message queues is configurable via the CONFIGPOSIXMQUEUE kernel  configu‐\nration option.  This option is enabled by default.\n\n#### Persistence\n\nPOSIX message queues have kernel persistence: if not removed by mqunlink(3), a message queue\nwill exist until the system is shut down.\n\n#### Linking\n\nPrograms using the POSIX message queue API must be compiled with cc -lrt to link against  the\nreal-time library, librt.\n\n#### /proc interfaces\n\nThe  following  interfaces can be used to limit the amount of kernel memory consumed by POSIX\nmessage queues and to set the default attributes for new message queues:\n\n/proc/sys/fs/mqueue/msgdefault (since Linux 3.5)\nThis file defines the value used for a new queue's mqmaxmsg setting when the queue is\ncreated  with a call to mqopen(3) where attr is specified as NULL.  The default value\nfor this file is 10.  The minimum and maximum are as for  /proc/sys/fs/mqueue/msgmax.\nA  new queue's default mqmaxmsg value will be the smaller of msgdefault and msgmax.\nUp until Linux 2.6.28, the default mqmaxmsg was 10; from Linux 2.6.28 to  Linux  3.4,\nthe default was the value defined for the msgmax limit.\n\n/proc/sys/fs/mqueue/msgmax\nThis  file  can be used to view and change the ceiling value for the maximum number of\nmessages in a queue.  This value acts as a ceiling  on  the  attr->mqmaxmsg  argument\ngiven to mqopen(3).  The default value for msgmax is 10.  The minimum value is 1 (10\nin kernels before 2.6.28).  The upper limit is HARDMSGMAX.  The msgmax limit is  ig‐\nnored for privileged processes (CAPSYSRESOURCE), but the HARDMSGMAX ceiling is nev‐\nertheless imposed.\n\nThe definition of HARDMSGMAX has changed across kernel versions:\n\n*  Up to Linux 2.6.32: 131072 / sizeof(void *)\n\n*  Linux 2.6.33 to 3.4: (32768 * sizeof(void *) / 4)\n\n*  Since Linux 3.5: 65,536\n\n/proc/sys/fs/mqueue/msgsizedefault (since Linux 3.5)\nThis file defines the value used for a new queue's mqmsgsize setting when  the  queue\nis  created  with  a  call to mqopen(3) where attr is specified as NULL.  The default\nvalue  for  this  file  is  8192  (bytes).   The  minimum  and  maximum  are  as   for\n/proc/sys/fs/mqueue/msgsizemax.    If  msgsizedefault  exceeds  msgsizemax,  a  new\nqueue's default mqmsgsize value is capped to the msgsizemax limit.  Up  until  Linux\n2.6.28,  the  default mqmsgsize was 8192; from Linux 2.6.28 to Linux 3.4, the default\nwas the value defined for the msgsizemax limit.\n\n/proc/sys/fs/mqueue/msgsizemax\nThis file can be used to view and change the ceiling  on  the  maximum  message  size.\nThis  value  acts  as  a ceiling on the attr->mqmsgsize argument given to mqopen(3).\nThe default value for msgsizemax is 8192 bytes.  The minimum value is  128  (8192  in\nkernels before 2.6.28).  The upper limit for msgsizemax has varied across kernel ver‐\nsions:\n\n*  Before Linux 2.6.28, the upper limit is INTMAX.\n\n*  From Linux 2.6.28 to 3.4, the limit is 1,048,576.\n\n*  Since Linux 3.5, the limit is 16,777,216 (HARDMSGSIZEMAX).\n\nThe msgsizemax limit is ignored for privileged process (CAPSYSRESOURCE), but, since\nLinux 3.5, the HARDMSGSIZEMAX ceiling is enforced for privileged processes.\n\n/proc/sys/fs/mqueue/queuesmax\nThis  file  can be used to view and change the system-wide limit on the number of mes‐\nsage queues that can be created.  The default value for queuesmax is 256.  No ceiling\nis imposed on the queuesmax limit; privileged processes (CAPSYSRESOURCE) can exceed\nthe limit (but see BUGS).\n\n#### Resource limit\n\nThe RLIMITMSGQUEUE resource limit, which places a limit on the amount of space that  can  be\nconsumed  by all of the message queues belonging to a process's real user ID, is described in\ngetrlimit(2).\n\n#### Mounting the message queue filesystem\n\nOn Linux, message queues are created in a virtual  filesystem.   (Other  implementations  may\nalso  provide  such a feature, but the details are likely to differ.)  This filesystem can be\nmounted (by the superuser) using the following commands:\n\n# mkdir /dev/mqueue\n# mount -t mqueue none /dev/mqueue\n\nThe sticky bit is automatically enabled on the mount directory.\n\nAfter the filesystem has been mounted, the message queues on the system can be viewed and ma‐\nnipulated using the commands usually used for files (e.g., ls(1) and rm(1)).\n\nThe  contents  of  each file in the directory consist of a single line containing information\nabout the queue:\n\n$ cat /dev/mqueue/mymq\nQSIZE:129     NOTIFY:2    SIGNO:0    NOTIFYPID:8260\n\nThese fields are as follows:\n\nQSIZE  Number of bytes of data in all messages in the queue (but see BUGS).\n\nNOTIFYPID\nIf this is nonzero, then the process with this PID has used mqnotify(3)  to  register\nfor asynchronous message notification, and the remaining fields describe how notifica‐\ntion occurs.\n\nNOTIFY Notification method: 0 is SIGEVSIGNAL; 1 is SIGEVNONE; and 2 is SIGEVTHREAD.\n\nSIGNO  Signal number to be used for SIGEVSIGNAL.\n\n#### Linux implementation of message queue descriptors\n\nOn Linux, a message queue descriptor is actually a file descriptor.  (POSIX does not  require\nsuch  an  implementation.)  This means that a message queue descriptor can be monitored using\nselect(2), poll(2), or epoll(7).  This is not portable.\n\nThe close-on-exec flag (see open(2)) is automatically set on the file descriptor returned  by\nmqopen(2).\n\n#### IPC namespaces\n\nFor  a  discussion  of the interaction of POSIX message queue objects and IPC namespaces, see\nipcnamespaces(7).\n\n### NOTES\n\nSystem V message queues (msgget(2), msgsnd(2), msgrcv(2), etc.) are an older API for exchang‐\ning  messages  between  processes.   POSIX message queues provide a better designed interface\nthan System V message queues; on the other hand POSIX message queues are less  widely  avail‐\nable (especially on older systems) than System V message queues.\n\nLinux  does  not  currently (2.6.26) support the use of access control lists (ACLs) for POSIX\nmessage queues.\n\n### BUGS\n\nIn Linux versions 3.5 to 3.14, the kernel imposed a ceiling of 1024 (HARDQUEUESMAX)  on  the\nvalue  to  which  the queuesmax limit could be raised, and the ceiling was enforced even for\nprivileged processes.  This ceiling value was removed in Linux 3.14, and  patches  to  stable\nkernels 3.5.x to 3.13.x also removed the ceiling.\n\nAs  originally  implemented  (and  documented), the QSIZE field displayed the total number of\n(user-supplied) bytes in all messages in the message queue.  Some changes in Linux 3.5  inad‐\nvertently  changed  the behavior, so that this field also included a count of kernel overhead\nbytes used to store the messages in the queue.  This behavioral regression was  rectified  in\nLinux  4.2  (and earlier stable kernel series), so that the count once more included just the\nbytes of user data in messages in the queue.\n\n### EXAMPLES\n\nAn example of the use of various message queue functions is shown in mqnotify(3).\n\n### SEE ALSO\n\ngetrlimit(2), mqgetsetattr(2), poll(2), select(2), mqclose(3), mqgetattr(3), mqnotify(3),\nmqopen(3), mqreceive(3), mqsend(3), mqunlink(3), epoll(7), namespaces(7)\n\n### COLOPHON\n\nThis  page  is  part  of  release  5.10 of the Linux man-pages project.  A description of the\nproject, information about reporting bugs, and the latest version of this page, can be  found\nat https://www.kernel.org/doc/man-pages/.\n\n\n\nLinux                                        2020-06-09                               MQOVERVIEW(7)\n\n"
        }
    ],
    "structuredContent": {
        "command": "mq_overview",
        "section": "7",
        "mode": "man",
        "summary": "mqoverview - overview of POSIX message queues",
        "synopsis": null,
        "flags": [],
        "examples": [
            "An example of the use of various message queue functions is shown in mqnotify(3)."
        ],
        "see_also": [
            {
                "name": "getrlimit",
                "section": "2",
                "url": "https://www.chedong.com/phpMan.php/man/getrlimit/2/json"
            },
            {
                "name": "mqgetsetattr",
                "section": "2",
                "url": "https://www.chedong.com/phpMan.php/man/mqgetsetattr/2/json"
            },
            {
                "name": "poll",
                "section": "2",
                "url": "https://www.chedong.com/phpMan.php/man/poll/2/json"
            },
            {
                "name": "select",
                "section": "2",
                "url": "https://www.chedong.com/phpMan.php/man/select/2/json"
            },
            {
                "name": "mqclose",
                "section": "3",
                "url": "https://www.chedong.com/phpMan.php/man/mqclose/3/json"
            },
            {
                "name": "mqgetattr",
                "section": "3",
                "url": "https://www.chedong.com/phpMan.php/man/mqgetattr/3/json"
            },
            {
                "name": "mqnotify",
                "section": "3",
                "url": "https://www.chedong.com/phpMan.php/man/mqnotify/3/json"
            },
            {
                "name": "mqopen",
                "section": "3",
                "url": "https://www.chedong.com/phpMan.php/man/mqopen/3/json"
            },
            {
                "name": "mqreceive",
                "section": "3",
                "url": "https://www.chedong.com/phpMan.php/man/mqreceive/3/json"
            },
            {
                "name": "mqsend",
                "section": "3",
                "url": "https://www.chedong.com/phpMan.php/man/mqsend/3/json"
            },
            {
                "name": "mqunlink",
                "section": "3",
                "url": "https://www.chedong.com/phpMan.php/man/mqunlink/3/json"
            },
            {
                "name": "epoll",
                "section": "7",
                "url": "https://www.chedong.com/phpMan.php/man/epoll/7/json"
            },
            {
                "name": "namespaces",
                "section": "7",
                "url": "https://www.chedong.com/phpMan.php/man/namespaces/7/json"
            }
        ],
        "section_outline": [
            {
                "name": "NAME",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "DESCRIPTION",
                "lines": 34,
                "subsections": [
                    {
                        "name": "Library interfaces and system calls",
                        "lines": 16
                    },
                    {
                        "name": "Versions",
                        "lines": 3
                    },
                    {
                        "name": "Kernel configuration",
                        "lines": 3
                    },
                    {
                        "name": "Persistence",
                        "lines": 3
                    },
                    {
                        "name": "Linking",
                        "lines": 3
                    },
                    {
                        "name": "/proc interfaces",
                        "lines": 58
                    },
                    {
                        "name": "Resource limit",
                        "lines": 4
                    },
                    {
                        "name": "Mounting the message queue filesystem",
                        "lines": 31
                    },
                    {
                        "name": "Linux implementation of message queue descriptors",
                        "lines": 7
                    },
                    {
                        "name": "IPC namespaces",
                        "lines": 3
                    }
                ]
            },
            {
                "name": "NOTES",
                "lines": 8,
                "subsections": []
            },
            {
                "name": "BUGS",
                "lines": 12,
                "subsections": []
            },
            {
                "name": "EXAMPLES",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "SEE ALSO",
                "lines": 3,
                "subsections": []
            },
            {
                "name": "COLOPHON",
                "lines": 7,
                "subsections": []
            }
        ]
    }
}