OSDN Git Service

ebdbb1f53f5c0730768f4c0e50172aef6e044ffa
[linuxjm/LDP_man-pages.git] / draft / man7 / mq_overview.7
1 '\" t
2 .\" Hey Emacs! This file is -*- nroff -*- source.
3 .\"
4 .\" Copyright (C) 2006 Michael Kerrisk <mtk.manpages@gmail.com>
5 .\"
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.
9 .\"
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.
14 .\"
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
21 .\" professionally.
22 .\"
23 .\" Formatted or processed versions of this manual, if unaccompanied by
24 .\" the source, must acknowledge the copyright and authors of this work.
25 .\"
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
31 .\"
32 .\"WORD:        message queue descriptor        メッセージキュー記述子
33 .\"WORD:        message queue description       メッセージキュー記述
34 .\"
35 .TH MQ_OVERVIEW 7 2009-09-27 "Linux" "Linux Programmer's Manual"
36 .\"O .SH NAME
37 .SH 名前
38 .\"O mq_overview \- Overview of POSIX message queues
39 mq_overview \- POSIX メッセージキューの概要
40 .\"O .SH DESCRIPTION
41 .SH 説明
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),
46 .\"O .BR msgsnd (2),
47 .\"O .BR msgrcv (2),
48 .\"O etc.), but provides similar functionality.
49 POSIX メッセージキューを使用すると、プロセス間で
50 メッセージの形でのデータのやり取りを行うことができる。
51 この API は System V メッセージキューの API
52 .RB ( msgget (2),
53 .BR msgsnd (2),
54 .BR msgrcv (2)
55 など) とは異なるものだが、同様の機能を提供する。
56
57 .\"O Message queues are created and opened using
58 .\"O .BR mq_open (3);
59 .\"O this function returns a
60 .\"O .I message queue descriptor
61 .\"O .RI ( mqd_t ),
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
64 .\"O .IR /somename ;
65 .\"O that is, a null-terminated string of up to
66 .\"O .BI NAME_MAX
67 .\"O (i.e., 255) characters consisting of an initial slash,
68 .\"O followed by one or more characters, none of which are slashes.
69 メッセージキューの作成とオープンは
70 .BR mq_open (3)
71 を使って行う。この関数は
72 .I メッセージキュー記述子 (message queue descriptor)
73 .RI ( mqd_t )
74 を返す。これ以降のコールでは、オープンされたメッセージキューは
75 .I メッセージキュー記述子
76 を使って参照される。
77 各メッセージキューは
78 .I /somename
79 の形の名前で区別することができる。
80 その名前は、最大で
81 .B NAME_MAX
82 (すなわち 255) 文字の NULL 終端された文字列で、
83 スラッシュで始まり、スラッシュ以外の文字が 1 文字以上続く形式である。
84 .\"O Two processes can operate on the same queue by passing the same name to
85 .\"O .BR mq_open (3).
86 .BR mq_open (3)
87 に同じ名前を渡すことで、2つのプロセスで同一のキューを
88 操作することができる。
89
90 .\"O Messages are transferred to and from a queue using
91 .\"O .BR mq_send (3)
92 .\"O and
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)
100 .\"O and
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).
105 メッセージのキューへの送受信は
106 .BR mq_send (3)
107
108 .BR mq_receive (3)
109 を使って行う。プロセスがキューの使用を終えるときには、
110 .BR mq_close (3)
111 を使ってキューをクローズする。キューがもはや不要となった場合には、
112 .BR mq_unlink (3)
113 を使ってキューを削除できる。キューの属性は
114 .BR mq_getattr (3)
115 で取得でき、 (制限はあるが)
116 .BR mq_setattr (3)
117 で変更できる。
118 .BR mq_notify (3)
119 を使うことで、空のキューへのメッセージ到着を非同期で
120 通知するように要求することもできる。
121
122 .\"O A message queue descriptor is a reference to an
123 .\"O .I "open message queue description"
124 .\"O (cf.
125 .\"O .BR open (2)).
126 .\"O After a
127 .\"O .BR fork (2),
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.
134 メッセージキュー記述子は
135 .I "オープンメッセージキュー記述 (open message queue description)"
136 への参照である
137 .RB ( open (2)
138 も参照)。
139 .BR fork (2)
140 実行後は、子プロセスは親プロセスのメッセージキュー記述子のコピーを継承する。
141 これらの記述子は、親プロセスの対応する記述子と同じオープンメッセージキュー
142 記述を参照している。親プロセスと子プロセスの対応する記述子は、フラグ
143 .RI ( mq_flags )
144 を共有する。なぜなら、フラグはオープンメッセージキュー記述に
145 関連付けられているからである。
146
147 .\"O Each message has an associated
148 .\"O .IR priority ,
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
153 .\"O (high).
154 .\"O On Linux,
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.
159 各メッセージにはそれぞれ
160 .I 優先度 (priority)
161 があり、メッセージの受信プロセスへの配送は常に
162 優先度の高いメッセージから順に行われる。
163 メッセージの優先度は 0 (低優先) から
164 .I sysconf(_SC_MQ_PRIO_MAX)\ -\ 1
165 (高優先) の値を持つ。
166 Linux では、
167 .I sysconf(_SC_MQ_PRIO_MAX)
168 は 32768 を返すが、
169 POSIX.1-2001 で要求されているのは 0 から 31 までの優先度を
170 実装することだけであり、実装によってはこの範囲の優先度しか
171 対応していない。
172 .PP
173 .\"O The remainder of this section describes some specific details
174 .\"O of the Linux implementation of POSIX message queues.
175 この節の残りでは、POSIX メッセージキューの Linux の実装の詳細
176 について説明する。
177 .\"O .SS Library interfaces and system calls
178 .SS ライブラリインタフェースとシステムコール
179 .\"O In most cases the
180 .\"O .B mq_*()
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:
184 ほとんどの場合、上記の
185 .B mq_*()
186 ライブラリインタフェースは、同じ名前の下位層のシステムコールを
187 使って実装されている。この枠組みにあてはまらないものを
188 以下の表に示す。
189 .in +4n
190 .TS
191 lB lB
192 l l.
193 Library interface       System call
194 mq_close(3)     close(2)
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)
204 .TE
205 .in
206 .\"O .SS Versions
207 .SS バージョン
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
213 .SS カーネルの設定
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)
219 オプション
220 .B CONFIG_POSIX_MQUEUE
221 で設定可能である。このオプションはデフォルトでは有効である。
222 .\"O .SS Persistence
223 .SS 持続性
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 メッセージキューはカーネル内で保持される。
229 .BR mq_unlink (3)
230 で削除されなければ、メッセージキューは
231 システムがシャットダウンされるまで存在し続ける。
232 .\"O .SS Linking
233 .SS リンク
234 .\"O Programs using the POSIX message queue API must be compiled with
235 .\"O .I cc \-lrt
236 .\"O to link against the real-time library,
237 .\"O .IR librt .
238 POSIX メッセージキュー API を使用したプログラムは
239 .I cc \-lrt
240 でコンパイルし、リアルタイムライブラリ
241 .I librt
242 とリンクしなければならない。
243 .\"O .SS /proc interfaces
244 .SS /proc インタフェース
245 .\"O The following interfaces can be used to limit the amount of
246 .\"O kernel memory consumed by POSIX message queues:
247 以下のインタフェースを使って、POSIX メッセージキューが消費するカーネル
248 メモリの量を制限することができる。
249 .TP
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
258 .\"O .I msg_max
259 .\"O is 10.
260 .\"O The minimum value is 1 (10 in kernels before 2.6.28).
261 .\"O The upper limit is
262 .\"O .BR HARD_MAX :
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 ),
267 .\"O but the
268 .\"O .B HARD_MAX
269 .\"O ceiling is nevertheless imposed.
270 このファイルを使って、一つのキューに入れられるメッセージの最大数の
271 上限値を参照したり変更したりできる。この値は、
272 .BR mq_open (3)
273 に渡す
274 .I attr\->mq_maxmsg
275 引き数に対する上限値として機能する。
276 .I msg_max
277 のデフォルト値は 10 で、
278 最小値は 1 (2.6.28 より前のカーネルでは 10) である。
279 上限は「埋め込みの固定値」
280 .RB ( HARD_MAX )
281
282 .IR "(131072\ /\ sizeof(void\ *))"
283 (Linux/86 では 32768) である。
284 この上限は特権プロセス
285 .RB ( CAP_SYS_RESOURCE )
286 では無視されるが、埋め込みの固定値による上限は
287 どんな場合にでも適用される。
288 .TP
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
297 .\"O .I msgsize_max
298 .\"O is 8192 bytes.
299 .\"O The minimum value is 128 (8192 in kernels before 2.6.28).
300 .\"O The upper limit for
301 .\"O .I msgsize_max
302 .\"O is 1,048,576 (in kernels before 2.6.28, the upper limit was
303 .\"O .BR INT_MAX ;
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 このファイルを使って、メッセージの最大サイズの上限値を       
308 参照したり変更したりできる。      
309 この値は、 
310 .BR mq_open (3) 
311 に渡す       
312 .I attr\->mq_msgsize
313 引き数に対する上限値として機能する。  
314 .I msgsize_max  
315 のデフォルト値は 8192 バイトで、
316 最小値は 128 (2.6.28 より前のカーネルでは 8192) である。
317 .I msgsize_max
318 の上限は 1,048,576 である
319 (2.6.28 より前のカーネルでは、上限は
320 .B INT_MAX
321 (Linux/86 では 2,147,483,647) であった)。
322 この上限は特権プロセス       
323 .RB ( CAP_SYS_RESOURCE )        
324 では無視される。
325 .TP
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
333 .\"O .I queues_max
334 .\"O is 256; it can be changed to any value in the range 0 to INT_MAX.
335 このファイルを使って、作成することができるメッセージキューの数に        
336 対するシステム全体での制限を参照したり変更したりできる。    
337 一度この上限に達すると、新しいメッセージキューを作成できるのは   
338 特権プロセス      
339 .RB ( CAP_SYS_RESOURCE )        
340 だけとなる。      
341 .I queues_max   
342 のデフォルト値は 256 であり、       
343 0 から INT_MAX の範囲の任意の値に変更することができる。
344 .\"O .SS Resource limit
345 .SS リソース制限
346 .\"O The
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).
352 リソース上限
353 .B RLIMIT_MSGQUEUE
354 は、プロセスの実 UID に対応する全メッセージキューが消費する
355 メモリ空間の量に対して上限を設定する。
356 .BR getrlimit (2)
357 を参照。
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
364 .\"O commands:
365 Linux では、メッセージキューは仮想ファイルシステム内に作成される
366 (他の実装でも同様の機能が提供されているものもあるが、
367 詳細は違っているだろう)。
368 以下のコマンドを使うことで (スーパーユーザは)
369 このファイルシステムをマウントできる:
370 .in +4n
371 .nf
372
373 .RB "#" " mkdir /dev/mqueue"
374 .RB "#" " mount \-t mqueue none /dev/mqueue"
375
376 .fi
377 .in
378 .\"O The sticky bit is automatically enabled on the mount directory.
379 マウントしたディレクトリのスティッキービット (sticky bit) は
380 自動的にオンとなる。
381
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
384 .\"O (e.g.,
385 .\"O .BR ls (1)
386 .\"O and
387 .\"O .BR rm (1)).
388 メッセージキュー・ファイルシステムのマウント後は、ファイルに対して
389 通常使うコマンド (例えば
390 .BR ls (1)
391
392 .BR rm (1))
393 を使って、システム上のメッセージキューを表示したり
394 操作したりできる。
395
396 .\"O The contents of each file in the directory consist of a single line
397 .\"O containing information about the queue:
398 ディレクトリ内の各ファイルの内容は 1行であり、
399 キューに関する情報が表示される。
400 .in +4n
401 .nf
402
403 .RB "$" " cat /dev/mqueue/mymq"
404 QSIZE:129     NOTIFY:2    SIGNO:0    NOTIFY_PID:8260
405
406 .fi
407 .in
408 .\"O These fields are as follows:
409 各フィールドの詳細は以下の通りである:
410 .TP
411 .B QSIZE
412 .\"O Number of bytes of data in all messages in the queue.
413 キューに入っている全メッセージの合計バイト数。
414 .TP
415 .B NOTIFY_PID
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 を持つプロセスが
421 .BR mq_notify (3)
422 を使って、非同期のメッセージ通知を行うように設定したことを示す。
423 どのように通知が行われるかは、以下のフィールドにより決定される。
424 .TP
425 .B NOTIFY
426 .\"O Notification method:
427 .\"O 0 is
428 .\"O .BR SIGEV_SIGNAL ;
429 .\"O 1 is
430 .\"O .BR SIGEV_NONE ;
431 .\"O and
432 .\"O 2 is
433 .\"O .BR SIGEV_THREAD .
434 通知方法:
435 0 は
436 .BR SIGEV_SIGNAL ;
437 1 は
438 .BR SIGEV_NONE ;
439 2 は
440 .B SIGEV_THREAD
441 .TP
442 .B SIGNO
443 .\"O Signal number to be used for
444 .\"O .BR SIGEV_SIGNAL .
445 .B SIGEV_SIGNAL
446 に使用されるシグナル番号。
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
451 .\"O .BR select (2),
452 .\"O .BR poll (2),
453 .\"O or
454 .\"O .BR epoll (7).
455 .\"O This is not portable.
456 Linux では、メッセージキュー記述子は実際はファイル記述子 (file descriptor)
457 であり、
458 .BR select (2),
459 .BR poll (2),
460 .BR epoll (7)
461 を使って監視することができる。
462 この機能の移植性はない。
463 .\"O .SH "CONFORMING TO"
464 .SH 準拠
465 POSIX.1-2001.
466 .\"O .SH NOTES
467 .SH 注意
468 .\"O System V message queues
469 .\"O .RB ( msgget (2),
470 .\"O .BR msgsnd (2),
471 .\"O .BR msgrcv (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.
477 System V メッセージキュー
478 .RB ( msgget (2),
479 .BR msgsnd (2),
480 .BR msgrcv (2)
481 など) はプロセス間でメッセージをやり取りするための古い API である。
482 POSIX メッセージキューは System V メッセージキューよりもうまく
483 設計されたインタフェースを提供している。
484 一方で、POSIX メッセージキューは System V メッセージキューと比べると
485 利用できるシステムが少ない (特に、古いシステムでは少ない)。
486
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) に
491 対応していない。
492 .\"O .SH EXAMPLE
493 .SH 例
494 .\"O An example of the use of various message queue functions is shown in
495 .\"O .BR mq_notify (3).
496 各種のメッセージキュー関数を使用した例が
497 .BR mq_notify (3)
498 に記載されている。
499 .\"O .SH "SEE ALSO"
500 .SH 関連項目
501 .BR getrlimit (2),
502 .BR mq_getsetattr (2),
503 .BR poll (2),
504 .BR select (2),
505 .BR mq_close (3),
506 .BR mq_getattr (3),
507 .BR mq_notify (3),
508 .BR mq_open (3),
509 .BR mq_receive (3),
510 .BR mq_send (3),
511 .BR mq_unlink (3),
512 .BR epoll (7)