Section: Linux Programmer's Manual (7)
POSIX message queues allow processes to exchange data in the form of messages. This API is distinct from that provided by System V message queues (msgget?(2), msgsnd?(2), msgrcv?(2), etc.), but provides similar functionality.
Message queues are created and opened using mq_open?(3); this function returns a message queue descriptor (mqd_t), which is used to refer to the open message queue in later calls. Each message queue is identified by a name of the form /somename; that is, a null-terminated string of up to NAME_MAX (i.e., 255) characters consisting of an initial slash, followed by one or more characters, none of which are slashes. Two processes can operate on the same queue by passing the same name to mq_open?(3).
Messages are transferred to and from a queue using mq_send?(3) and mq_receive?(3). When a process has finished using the queue, it closes it using mq_close?(3), and when the queue is no longer required, it can be deleted using mq_unlink?(3). Queue attributes can be retrieved and (in some cases) modified using mq_getattr?(3) and mq_setattr?(3). A process can request asynchronous notification of the arrival of a message on a previously empty queue using mq_notify?(3).
A message queue descriptor is a reference to an open message queue description (cf. open?(2)). After a fork?(2), a child inherits copies of its parent's message queue descriptors, and these descriptors refer to the same open message queue descriptions as the corresponding descriptors in the parent. Corresponding descriptors in the two processes share the flags (mq_flags) that are associated with the open message queue description.
Each message has an associated priority, and messages are always delivered to the receiving process highest priority first. Message priorities range from 0 (low) to sysconf(_SC_MQ_PRIO_MAX) - 1 (high). On Linux, sysconf(_SC_MQ_PRIO_MAX) returns 32768, but POSIX.1-2001 requires only that an implementation support at least priorities in the range 0 to 31; some implementations provide only this range.
In most cases the mq_*() library interfaces listed above are implemented on top of underlying system calls of the same name. Deviations from this scheme are indicated in the following table:
:<TABLE> <TR VALIGN="top| <TD CLASS="c1|Library interface</TD> <TD>System call
</TD> </TR> </TABLE> :
The following interfaces can be used to limit the amount of kernel memory consumed by POSIX message queues and to set the default attributes for new message queues:
The definition of HARD_MSGMAX has changed across kernel versions:
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:
The sticky bit is automatically enabled on the mount directory.
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:
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.
In Linux versions 3.5 to 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 kernels 3.5.x to 3.13.x also removed the ceiling.
This page is part of release 3.74 of the Linux man-pages project. A description of the project, information about reporting bugs, and the latest version of this page, can be found at http://www.kernel.org/doc/man-pages/.
Tutoriais de Tecnologia Web