2 .\" Hey Emacs! This file is -*- nroff -*- source.
4 .\" Copyright (C) 2006 Michael Kerrisk <mtk.manpages@gmail.com>
6 .\" Permission is granted to make and distribute verbatim copies of this
7 .\" manual provided the copyright notice and this permission notice are
8 .\" preserved on all copies.
10 .\" Permission is granted to copy and distribute modified versions of this
11 .\" manual under the conditions for verbatim copying, provided that the
12 .\" entire resulting derived work is distributed under the terms of a
13 .\" permission notice identical to this one.
15 .\" Since the Linux kernel and libraries are constantly changing, this
16 .\" manual page may be incorrect or out-of-date. The author(s) assume no
17 .\" responsibility for errors or omissions, or for damages resulting from
18 .\" the use of the information contained herein. The author(s) may not
19 .\" have taken the same level of care in the production of this manual,
20 .\" which is licensed free of charge, as they might when working
23 .\" Formatted or processed versions of this manual, if unaccompanied by
24 .\" the source, must acknowledge the copyright and authors of this work.
26 .\" Japanese Version Copyright (c) 2006 Akihiro MOTOKI all rights reserved.
27 .\" Translated 2006-03-13, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
28 .\" Updated 2006-07-20, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>, LDP v2.36
29 .\" Updated 2009-02-23, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>, LDP v3.19
30 .\" Updated 2010-04-11, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>, LDP v3.24
32 .\"WORD: message queue descriptor メッセージキュー記述子
33 .\"WORD: message queue description メッセージキュー記述
35 .TH MQ_OVERVIEW 7 2009-09-27 "Linux" "Linux Programmer's Manual"
38 .\"O mq_overview \- Overview of POSIX message queues
39 mq_overview \- POSIX メッセージキューの概要
42 .\"O POSIX message queues allow processes to exchange data in
43 .\"O the form of messages.
44 .\"O This API is distinct from that provided by System V message queues
45 .\"O .RB ( msgget (2),
48 .\"O etc.), but provides similar functionality.
49 POSIX メッセージキューを使用すると、プロセス間で
50 メッセージの形でのデータのやり取りを行うことができる。
51 この API は System V メッセージキューの API
55 など) とは異なるものだが、同様の機能を提供する。
57 .\"O Message queues are created and opened using
59 .\"O this function returns a
60 .\"O .I message queue descriptor
62 .\"O which is used to refer to the open message queue in later calls.
63 .\"O Each message queue is identified by a name of the form
65 .\"O that is, a null-terminated string of up to
67 .\"O (i.e., 255) characters consisting of an initial slash,
68 .\"O followed by one or more characters, none of which are slashes.
72 .I メッセージキュー記述子 (message queue descriptor)
74 を返す。これ以降のコールでは、オープンされたメッセージキューは
82 (すなわち 255) 文字の NULL 終端された文字列で、
83 スラッシュで始まり、スラッシュ以外の文字が 1 文字以上続く形式である。
84 .\"O Two processes can operate on the same queue by passing the same name to
87 に同じ名前を渡すことで、2つのプロセスで同一のキューを
90 .\"O Messages are transferred to and from a queue using
93 .\"O .BR mq_receive (3).
94 .\"O When a process has finished using the queue, it closes it using
95 .\"O .BR mq_close (3),
96 .\"O and when the queue is no longer required, it can be deleted using
97 .\"O .BR mq_unlink (3).
98 .\"O Queue attributes can be retrieved and (in some cases) modified using
99 .\"O .BR mq_getattr (3)
101 .\"O .BR mq_setattr (3).
102 .\"O A process can request asynchronous notification
103 .\"O of the arrival of a message on a previously empty queue using
104 .\"O .BR mq_notify (3).
109 を使って行う。プロセスがキューの使用を終えるときには、
111 を使ってキューをクローズする。キューがもはや不要となった場合には、
113 を使ってキューを削除できる。キューの属性は
119 を使うことで、空のキューへのメッセージ到着を非同期で
122 .\"O A message queue descriptor is a reference to an
123 .\"O .I "open message queue description"
128 .\"O a child inherits copies of its parent's message queue descriptors,
129 .\"O and these descriptors refer to the same open message queue descriptions
130 .\"O as the corresponding descriptors in the parent.
131 .\"O Corresponding descriptors in the two processes share the flags
132 .\"O .RI ( mq_flags )
133 .\"O that are associated with the open message queue description.
135 .I "オープンメッセージキュー記述 (open message queue description)"
140 実行後は、子プロセスは親プロセスのメッセージキュー記述子のコピーを継承する。
141 これらの記述子は、親プロセスの対応する記述子と同じオープンメッセージキュー
142 記述を参照している。親プロセスと子プロセスの対応する記述子は、フラグ
144 を共有する。なぜなら、フラグはオープンメッセージキュー記述に
147 .\"O Each message has an associated
149 .\"O and messages are always delivered to the receiving process
150 .\"O highest priority first.
151 .\"O Message priorities range from 0 (low) to
152 .\"O .I sysconf(_SC_MQ_PRIO_MAX)\ -\ 1
155 .\"O .I sysconf(_SC_MQ_PRIO_MAX)
156 .\"O returns 32768, but POSIX.1-2001 only requires
157 .\"O an implementation to support priorities in the range 0 to 31;
158 .\"O some implementations only provide this range.
161 があり、メッセージの受信プロセスへの配送は常に
163 メッセージの優先度は 0 (低優先) から
164 .I sysconf(_SC_MQ_PRIO_MAX)\ -\ 1
167 .I sysconf(_SC_MQ_PRIO_MAX)
169 POSIX.1-2001 で要求されているのは 0 から 31 までの優先度を
170 実装することだけであり、実装によってはこの範囲の優先度しか
173 .\"O The remainder of this section describes some specific details
174 .\"O of the Linux implementation of POSIX message queues.
175 この節の残りでは、POSIX メッセージキューの Linux の実装の詳細
177 .\"O .SS Library interfaces and system calls
178 .SS ライブラリインタフェースとシステムコール
179 .\"O In most cases the
181 .\"O library interfaces listed above are implemented
182 .\"O on top of underlying system calls of the same name.
183 .\"O Deviations from this scheme are indicated in the following table:
186 ライブラリインタフェースは、同じ名前の下位層のシステムコールを
187 使って実装されている。この枠組みにあてはまらないものを
193 Library interface System call
195 mq_getattr(3) mq_getsetattr(2)
196 mq_notify(3) mq_notify(2)
197 mq_open(3) mq_open(2)
198 mq_receive(3) mq_timedreceive(2)
199 mq_send(3) mq_timedsend(2)
200 mq_setattr(3) mq_getsetattr(2)
201 mq_timedreceive(3) mq_timedreceive(2)
202 mq_timedsend(3) mq_timedsend(2)
203 mq_unlink(3) mq_unlink(2)
208 .\"O POSIX message queues have been supported on Linux since kernel 2.6.6.
209 .\"O Glibc support has been provided since version 2.3.4.
210 Linux では POSIX メッセージキューはカーネル 2.6.6 以降でサポートされている。
211 glibc ではバージョン 2.3.4 以降でサポートされている。
212 .\"O .SS Kernel configuration
214 .\"O Support for POSIX message queues is configurable via the
215 .\"O .B CONFIG_POSIX_MQUEUE
216 .\"O kernel configuration option.
217 .\"O This option is enabled by default.
218 POSIX メッセージキューのサポートは、カーネルの設定 (configuration)
220 .B CONFIG_POSIX_MQUEUE
221 で設定可能である。このオプションはデフォルトでは有効である。
224 .\"O POSIX message queues have kernel persistence:
225 .\"O if not removed by
226 .\"O .BR mq_unlink (3),
227 .\"O a message queue will exist until the system is shut down.
228 POSIX メッセージキューはカーネル内で保持される。
231 システムがシャットダウンされるまで存在し続ける。
234 .\"O Programs using the POSIX message queue API must be compiled with
236 .\"O to link against the real-time library,
238 POSIX メッセージキュー API を使用したプログラムは
243 .\"O .SS /proc interfaces
245 .\"O The following interfaces can be used to limit the amount of
246 .\"O kernel memory consumed by POSIX message queues:
247 以下のインタフェースを使って、POSIX メッセージキューが消費するカーネル
250 .I /proc/sys/fs/mqueue/msg_max
251 .\"O This file can be used to view and change the ceiling value for the
252 .\"O maximum number of messages in a queue.
253 .\"O This value acts as a ceiling on the
254 .\"O .I attr\->mq_maxmsg
255 .\"O argument given to
256 .\"O .BR mq_open (3).
257 .\"O The default value for
260 .\"O The minimum value is 1 (10 in kernels before 2.6.28).
261 .\"O The upper limit is
263 .\"O .IR "(131072\ /\ sizeof(void\ *))"
264 .\"O (32768 on Linux/86).
265 .\"O This limit is ignored for privileged processes
266 .\"O .RB ( CAP_SYS_RESOURCE ),
269 .\"O ceiling is nevertheless imposed.
270 このファイルを使って、一つのキューに入れられるメッセージの最大数の
271 上限値を参照したり変更したりできる。この値は、
278 最小値は 1 (2.6.28 より前のカーネルでは 10) である。
282 .IR "(131072\ /\ sizeof(void\ *))"
283 (Linux/86 では 32768) である。
285 .RB ( CAP_SYS_RESOURCE )
286 では無視されるが、埋め込みの固定値による上限は
289 .I /proc/sys/fs/mqueue/msgsize_max
290 .\"O This file can be used to view and change the ceiling on the
291 .\"O maximum message size.
292 .\"O This value acts as a ceiling on the
293 .\"O .I attr\->mq_msgsize
294 .\"O argument given to
295 .\"O .BR mq_open (3).
296 .\"O The default value for
299 .\"O The minimum value is 128 (8192 in kernels before 2.6.28).
300 .\"O The upper limit for
302 .\"O is 1,048,576 (in kernels before 2.6.28, the upper limit was
304 .\"O that is, 2,147,483,647 on Linux/86).
305 .\"O This limit is ignored for privileged processes
306 .\"O .RB ( CAP_SYS_RESOURCE ).
307 このファイルを使って、メッセージの最大サイズの上限値を
316 最小値は 128 (2.6.28 より前のカーネルでは 8192) である。
319 (2.6.28 より前のカーネルでは、上限は
321 (Linux/86 では 2,147,483,647) であった)。
323 .RB ( CAP_SYS_RESOURCE )
326 .I /proc/sys/fs/mqueue/queues_max
327 .\"O This file can be used to view and change the system-wide limit on the
328 .\"O number of message queues that can be created.
329 .\"O Only privileged processes
330 .\"O .RB ( CAP_SYS_RESOURCE )
331 .\"O can create new message queues once this limit has been reached.
332 .\"O The default value for
334 .\"O is 256; it can be changed to any value in the range 0 to INT_MAX.
335 このファイルを使って、作成することができるメッセージキューの数に
336 対するシステム全体での制限を参照したり変更したりできる。
337 一度この上限に達すると、新しいメッセージキューを作成できるのは
339 .RB ( CAP_SYS_RESOURCE )
343 0 から INT_MAX の範囲の任意の値に変更することができる。
344 .\"O .SS Resource limit
347 .\"O .B RLIMIT_MSGQUEUE
348 .\"O resource limit, which places a limit on the amount of space
349 .\"O that can be consumed by all of the message queues
350 .\"O belonging to a process's real user ID, is described in
351 .\"O .BR getrlimit (2).
354 は、プロセスの実 UID に対応する全メッセージキューが消費する
358 .\"O .SS Mounting the message queue file system
359 .SS メッセージキュー・ファイルシステムのマウント
360 .\"O On Linux, message queues are created in a virtual file system.
361 .\"O (Other implementations may also provide such a feature,
362 .\"O but the details are likely to differ.)
363 .\"O This file system can be mounted (by the superuser) using the following
365 Linux では、メッセージキューは仮想ファイルシステム内に作成される
366 (他の実装でも同様の機能が提供されているものもあるが、
368 以下のコマンドを使うことで (スーパーユーザは)
373 .RB "#" " mkdir /dev/mqueue"
374 .RB "#" " mount \-t mqueue none /dev/mqueue"
378 .\"O The sticky bit is automatically enabled on the mount directory.
379 マウントしたディレクトリのスティッキービット (sticky bit) は
382 .\"O After the file system has been mounted, the message queues on the system
383 .\"O can be viewed and manipulated using the commands usually used for files
388 メッセージキュー・ファイルシステムのマウント後は、ファイルに対して
393 を使って、システム上のメッセージキューを表示したり
396 .\"O The contents of each file in the directory consist of a single line
397 .\"O containing information about the queue:
398 ディレクトリ内の各ファイルの内容は 1行であり、
403 .RB "$" " cat /dev/mqueue/mymq"
404 QSIZE:129 NOTIFY:2 SIGNO:0 NOTIFY_PID:8260
408 .\"O These fields are as follows:
412 .\"O Number of bytes of data in all messages in the queue.
413 キューに入っている全メッセージの合計バイト数。
416 .\"O If this is nonzero, then the process with this PID has used
417 .\"O .BR mq_notify (3)
418 .\"O to register for asynchronous message notification,
419 .\"O and the remaining fields describe how notification occurs.
420 この値が 0 以外の場合、この値の PID を持つプロセスが
422 を使って、非同期のメッセージ通知を行うように設定したことを示す。
423 どのように通知が行われるかは、以下のフィールドにより決定される。
426 .\"O Notification method:
428 .\"O .BR SIGEV_SIGNAL ;
430 .\"O .BR SIGEV_NONE ;
433 .\"O .BR SIGEV_THREAD .
443 .\"O Signal number to be used for
444 .\"O .BR SIGEV_SIGNAL .
447 .\"O .SS Polling message queue descriptors
448 .SS メッセージキュー記述子のポーリング
449 .\"O On Linux, a message queue descriptor is actually a file descriptor,
450 .\"O and can be monitored using
455 .\"O This is not portable.
456 Linux では、メッセージキュー記述子は実際はファイル記述子 (file descriptor)
463 .\"O .SH "CONFORMING TO"
468 .\"O System V message queues
469 .\"O .RB ( msgget (2),
472 .\"O etc.) are an older API for exchanging messages between processes.
473 .\"O POSIX message queues provide a better designed interface than
474 .\"O System V message queues;
475 .\"O on the other hand POSIX message queues are less widely available
476 .\"O (especially on older systems) than System V message queues.
481 など) はプロセス間でメッセージをやり取りするための古い API である。
482 POSIX メッセージキューは System V メッセージキューよりもうまく
484 一方で、POSIX メッセージキューは System V メッセージキューと比べると
485 利用できるシステムが少ない (特に、古いシステムでは少ない)。
487 .\"O Linux does not currently (2.6.26) support the use of access control
488 .\"O lists (ACLs) for POSIX message queues.
489 現在のことろ (バージョン 2.6.26 時点)、
490 Linux は POSIX メッセージキューに対するアクセス制御リスト (ACL) に
494 .\"O An example of the use of various message queue functions is shown in
495 .\"O .BR mq_notify (3).
502 .BR mq_getsetattr (2),