Manual Pages for Linux CentOS command on man mq_overview
MyWebUniversity

Manual Pages for Linux CentOS command on man mq_overview

MQOVERVIEW(7) Linux Programmer's Manual MQOVERVIEW(7)

NAME

mqoverview - overview of POSIX message queues DESCRIPTION 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 mqopen(3); this function returns a message queue descriptor (mqdt), which is used to refer to the open message queue in later calls. Each message queue is identi‐

fied by a name of the form /somename; that is, a null-terminated string of up to NAMEMAX (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 mqopen(3). Messages are transferred to and from a queue using mqsend(3) and mqreceive(3). When a process has finished using the queue, it closes it using mqclose(3), and when the queue is no longer required, it can be deleted using mqunlink(3). Queue attributes can be retrieved and (in some cases) modified using mqgetattr(3) and mqsetattr(3). A process can request asynchronous notification of the arrival of a mes‐ sage on a previously empty queue using mqnotify(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 pro‐ cesses share the flags (mqflags) that are associated with the open message queue description. Each message has an associated priority, and messages are always deliv‐ ered to the receiving process highest priority first. Message priori‐

ties range from 0 (low) to sysconf(SCMQPRIOMAX) - 1 (high). On

Linux, sysconf(SCMQPRIOMAX) 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. The remainder of this section describes some 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 imple‐ mented on top of underlying system calls of the same name. Deviations from this scheme are indicated in the following table: Library interface System call mqclose(3) close(2) mqgetattr(3) mqgetsetattr(2) mqnotify(3) mqnotify(2) mqopen(3) mqopen(2) mqreceive(3) mqtimedreceive(2) mqsend(3) mqtimedsend(2) mqsetattr(3) mqgetsetattr(2) mqtimedreceive(3) mqtimedreceive(2) mqtimedsend(3) mqtimedsend(2) mqunlink(3) mqunlink(2) Versions POSIX message queues have been supported on Linux since kernel 2.6.6. Glibc support has been provided since version 2.3.4. Kernel configuration Support for POSIX message queues is configurable via the CON‐ FIGPOSIXMQUEUE kernel configuration option. This option is enabled by default. Persistence POSIX message queues have kernel persistence: if not removed by mqunlink(3), a message queue will exist until the system is shut down. Linking Programs using the POSIX message queue API must be compiled with cc

-lrt to link against the real-time library, librt. /proc interfaces The following interfaces can be used to limit the amount of kernel mem‐ ory consumed by POSIX message queues: /proc/sys/fs/mqueue/msgmax 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->mqmaxmsg argument given to mqopen(3). The default value for msgmax is 10. The minimum value is 1 (10 in kernels before 2.6.28). The upper limit is HARDMAX: (131072 / sizeof(void *)) (32768 on Linux/86). This limit is ignored for privileged processes (CAPSYSRESOURCE), but the HARDMAX ceiling is nevertheless imposed. /proc/sys/fs/mqueue/msgsizemax This file can be used to view and change the ceiling on the max‐ imum message size. This value acts as a ceiling on the

attr->mqmsgsize argument given to mqopen(3). The default value for msgsizemax is 8192 bytes. The minimum value is 128 (8192 in kernels before 2.6.28). The upper limit for msg‐ sizemax is 1,048,576 (in kernels before 2.6.28, the upper limit was INTMAX; that is, 2,147,483,647 on Linux/86). This limit is ignored for privileged processes (CAPSYSRESOURCE). /proc/sys/fs/mqueue/queuesmax

This file can be used to view and change the system-wide limit on the number of message queues that can be created. Only priv‐ ileged processes (CAPSYSRESOURCE) can create new message queues once this limit has been reached. The default value for queuesmax is 256; it can be changed to any value in the range 0 to INTMAX. Resource limit The RLIMITMSGQUEUE resource limit, which 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, is described in getrlimit(2). Mounting the message queue file system On Linux, message queues are created in a virtual file system. (Other implementations may also provide such a feature, but the details are likely to differ.) This file system 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. After the file system has been mounted, the message queues on the sys‐ tem can be viewed and manipulated using the commands usually used 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 NOTIFYPID:8260 These fields are as follows: QSIZE Number of bytes of data in all messages in the queue. NOTIFYPID If this is nonzero, then the process with this PID has used mqnotify(3) to register for asynchronous message notification, and the remaining fields describe how notification occurs. NOTIFY Notification method: 0 is SIGEVSIGNAL; 1 is SIGEVNONE; and 2 is SIGEVTHREAD. SIGNO Signal number to be used for SIGEVSIGNAL. Polling message queue descriptors On Linux, a message queue descriptor is actually a file descriptor, and can be monitored using select(2), poll(2), or epoll(7). This is not portable. CONFORMING TO

POSIX.1-2001. 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 avail‐ able (especially on older systems) than System V message queues. Linux does not currently (2.6.26) support the use of access control lists (ACLs) for POSIX message queues. EXAMPLE An example of the use of various message queue functions is shown in mqnotify(3). SEE ALSO getrlimit(2), mqgetsetattr(2), poll(2), select(2), mqclose(3), mqgetattr(3), mqnotify(3), mqopen(3), mqreceive(3), mqsend(3), mqunlink(3), epoll(7) COLOPHON

This page is part of release 3.53 of the Linux man-pages project. A description of the project, and information about reporting bugs, can

be found at http://www.kernel.org/doc/man-pages/.

Linux 2009-09-27 MQOVERVIEW(7)




Contact us      |      About us      |      Term of use      |       Copyright © 2000-2019 MyWebUniversity.com ™