OSDN Git Service

5de79e37bebdf86f7ed23c1a2ba4ed147f7ce70e
[linuxjm/LDP_man-pages.git] / release / man2 / msgop.2
1 .\" Copyright 1993 Giorgio Ciucci <giorgio@crcc.it>
2 .\"
3 .\" %%%LICENSE_START(VERBATIM)
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
7 .\"
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
12 .\"
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein.  The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
19 .\" professionally.
20 .\"
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
23 .\" %%%LICENSE_END
24 .\"
25 .\" Modified Tue Oct 22 16:40:11 1996 by Eric S. Raymond <esr@thyrsus.com>
26 .\" Modified Mon Jul 10 21:09:59 2000 by aeb
27 .\" Modified 1 Jun 2002, Michael Kerrisk <mtk.manpages@gmail.com>
28 .\"     Language clean-ups.
29 .\"     Enhanced and corrected information on msg_qbytes, MSGMNB and MSGMAX
30 .\"     Added note on restart behavior of msgsnd() and msgrcv()
31 .\"     Formatting clean-ups (argument and field names marked as .I
32 .\"             instead of .B)
33 .\" Modified, 27 May 2004, Michael Kerrisk <mtk.manpages@gmail.com>
34 .\"     Added notes on capability requirements
35 .\" Modified, 11 Nov 2004, Michael Kerrisk <mtk.manpages@gmail.com>
36 .\"     Language and formatting clean-ups
37 .\"     Added notes on /proc files
38 .\" FIXME . Add example programs to this page.
39 .\"
40 .\"*******************************************************************
41 .\"
42 .\" This file was generated with po4a. Translate the source file.
43 .\"
44 .\"*******************************************************************
45 .\"
46 .\" Japanese Version Copyright (c) 1997 HANATAKA Shinya
47 .\"         all rights reserved.
48 .\" Translated 1997-02-23, HANATAKA Shinya <hanataka@abyss.rim.or.jp>
49 .\" Modified 2000-09-23, HANATAKA Shinya <hanataka@abyss.rim.or.jp>
50 .\" Updated 2002-11-26, Kentaro Shirakata <argrath@ub32.org>
51 .\" Updated 2005-03-04, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
52 .\" Updated 2006-03-05, Akihiro MOTOKI, LDP v2.25
53 .\" Updated 2008-08-09, Akihiro MOTOKI, LDP v3.05
54 .\" Updated 2013-05-01, Akihiro MOTOKI <amotoki@gmail.com>
55 .\"
56 .TH MSGOP 2 2014\-03\-17 Linux "Linux Programmer's Manual"
57 .SH 名前
58 msgrcv, msgsnd \- System V メッセージキュー操作
59 .SH 書式
60 .nf
61 \fB#include <sys/types.h>\fP
62 \fB#include <sys/ipc.h>\fP
63 \fB#include <sys/msg.h>\fP
64 .sp
65 \fBint msgsnd(int \fP\fImsqid\fP\fB, const void *\fP\fImsgp\fP\fB, size_t \fP\fImsgsz\fP\fB, int \fP\fImsgflg\fP\fB);\fP
66 .sp
67 \fBssize_t msgrcv(int \fP\fImsqid\fP\fB, void *\fP\fImsgp\fP\fB, size_t \fP\fImsgsz\fP\fB, long \fP\fImsgtyp\fP\fB,\fP
68 \fB               int \fP\fImsgflg\fP\fB);\fP
69 .fi
70 .SH 説明
71 システムコール \fBmsgsnd\fP()  と \fBmsgrcv\fP()  はそれぞれ、 System V メッセージ・キューへのメッセージの送信と、
72 メッセージの受信に使用される。呼び出し元プロセスは、 メッセージを送信するためにはメッセージ・キューに対する書き込み許可を、
73 メッセージを受信するためには読み出し許可を持っていなければならない。
74 .PP
75 呼び出し元プロセスは以下に示す構造体を用意し、この構造体への ポインタを \fImsgp\fP 引き数として渡す。
76 .in +4n
77 .nf
78
79 struct msgbuf {
80     long mtype;       /* message type, must be > 0 */
81     char mtext[1];    /* message data */
82 };
83 .fi
84 .in
85 .PP
86 \fImtext\fP フィールドは配列 (または他の構造体) で、その大きさは 非負の整数である \fImsgsz\fP で指定される。 長さ 0 のメッセージ
87 (つまり \fImtext\fP フィールドがないメッセージ) も認められている。 \fBmtype\fP フィールドは厳密に正の整数でなければならない。
88 この値は、メッセージを受信するプロセスでメッセージを選択するために 使用される (下記の \fBmsgrcv\fP()  の説明を参照のこと)。
89 .SS msgsnd()
90 \fBmsgsnd\fP()  システムコールは \fImsgp\fP 引き数で指定されたメッセージのコピーを \fImsqid\fP
91 で指定された識別子を持つメッセージ・キューへ追加する。
92 .PP
93 キューに十分な空き容量がある場合、 \fBmsgsnd\fP()  は直ちに成功する。 (キューの容量は、メッセージ・キューのデータ構造体の
94 \fImsg_qbytes\fP フィールドで定義される。 キュー作成時にこのフィールドは \fBMSGMNB\fP に初期化されるが、この制限は
95 \fBmsgctl\fP(2)  を使って変更できる。)  キューに十分な空き容量がない場合、 デフォルトでは \fBmsgsnd\fP()
96 は空き容量ができるまで停止 (block) する。 \fImsgflg\fP に \fBIPC_NOWAIT\fP が指定された場合は、エラー \fBEAGAIN\fP
97 で失敗する。
98
99 停止している \fBmsgsnd\fP()  は以下の場合にも失敗する。
100 .IP * 2
101 キューが削除された。 この場合、 \fIerrno\fP は \fBEIDRM\fP に設定される。
102 .IP *
103 シグナルが捕捉された。 この場合、 \fIerrno\fP は \fBEINTR\fP に設定される。 \fBsignal\fP(7)  参照。 (\fBmsgsnd\fP()
104 は、たとえシグナルハンドラの設定時に \fBSA_RESTART\fP を指定していたとしても、シグナルハンドラによって割り込まれた後で
105 自動的に再スタートすることは決してない。)
106 .PP
107 正常に終了した場合、メッセージ・キューのデータ構造体は以下のように 更新される:
108 .IP
109 \fImsg_lspid\fP には呼び出し元プロセスのプロセス ID が設定される。
110 .IP
111 \fImsg_qnum\fP は 1 増加する。
112 .IP
113 \fImsg_stime\fP には現在時刻が設定される。
114 .SS msgrcv()
115 \fBmsgrcv\fP()  システムコールは \fImsqid\fP で指定されたキューからメッセージを削除し、 \fImsgp\fP
116 で指定されたバッファにそのメッセージを格納する。
117 .PP
118 \fImsgsz\fP 引き数には \fImsgp\fP 引き数で指定された構造体の \fImtext\fP メンバーの最大のバイト数を指定する。
119 メッセージのテキストの長さが \fImsgsz\fP より大きい場合の動作は、 \fImsgflg\fP に \fBMSG_NOERROR\fP
120 が指定されているかどうかで決まる。 \fBMSG_NOERROR\fP が指定されていれば、メッセージのテキストは切り詰められる
121 (切り捨てられた部分は失われる)。 \fBMSG_NOERROR\fP が指定されていなければ、メッセージはキューから削除されず、 システムコールは \-1
122 を返して失敗し、 \fIerrno\fP に \fBE2BIG\fP が設定される。
123 .PP
124 Unless \fBMSG_COPY\fP is specified in \fImsgflg\fP (see below), the \fImsgtyp\fP
125 argument specifies the type of message requested, as follows:
126 .IP * 2
127 \fImsgtyp\fP が 0 ならば、キューの最初にあるメッセージが読み込まれる。
128 .IP *
129 \fImsgtyp\fP が 0 より大きい場合、 \fImsgflg\fP に \fBMSG_EXCEPT\fP が指定されていなければ、 \fImsgtyp\fP
130 型のキューの最初のメッセージが読み込まれる。 \fBMSG_EXCEPT\fP が指定された場合は、 \fImsgtyp\fP
131 型以外のキューの最初のメッセージが読み込まれる。
132 .IP *
133 \fImsgtyp\fP が 0 より小さければ、 \fImsgtyp\fP の絶対値以下で最も小さい型を持つキューの最初のメッセージが読み込まれる。
134 .PP
135 \fImsgflg\fP 引き数には、以下のフラグを任意の数だけ (0個も可)、これらの OR で指定する:
136 .TP 
137 \fBIPC_NOWAIT\fP
138 キューに要求された型のメッセージがない場合には直ちに返る。 システムコールは失敗し、 \fIerrno\fP には \fBENOMSG\fP が設定される。
139 .TP 
140 \fBMSG_COPY\fP (Linux 3.8 以降)
141 .\" commit 4a674f34ba04a002244edaf891b5da7fc1473ae8
142 Nondestructively fetch a copy of the message at the ordinal position in the
143 queue specified by \fImsgtyp\fP (messages are considered to be numbered
144 starting at 0).
145
146 This flag must be specified in conjunction with \fBIPC_NOWAIT\fP, with the
147 result that, if there is no message available at the given position, the
148 call fails immediately with the error \fBENOMSG\fP.  Because they alter the
149 meaning of \fImsgtyp\fP in orthogonal ways, \fBMSG_COPY\fP and \fBMSG_EXCEPT\fP may
150 not both be specified in \fImsgflg\fP.
151
152 The \fBMSG_COPY\fP flag was added for the implementation of the kernel
153 checkpoint\-restore facility and is available only if the kernel was built
154 with the \fBCONFIG_CHECKPOINT_RESTORE\fP option.
155 .TP 
156 \fBMSG_EXCEPT\fP
157 0 より大きな \fImsgtyp\fP と一緒に使用して、 \fImsgtyp\fP 以外のキューの最初のメッセージを読み込む。
158 .TP 
159 \fBMSG_NOERROR\fP
160 \fImsgsz\fP バイトよりも長かった場合はメッセージのテキストを切り詰める。
161 .PP
162 要求された型のメッセージが存在せず、 \fImsgflg\fP に \fBIPC_NOWAIT\fP が指定されていなかった場合、呼び出し元プロセスは
163 以下のいずれかの状況になるまで停止 (block) される:
164 .IP * 2
165 要求している型のメッセージがキューへ入れられた。
166 .IP *
167 メッセージ・キューがシステムから削除された。 この場合、システムコールは失敗し、 \fIerrno\fP に \fBEIDRM\fP が設定される。
168 .IP *
169 呼び出し元プロセスがシグナルを捕獲した。 この場合、システムコールは失敗し、 \fIerrno\fP に \fBEINTR\fP が設定される。
170 (\fBmsgrcv\fP()  は、たとえシグナルハンドラの設定時に \fBSA_RESTART\fP
171 を指定していたとしても、シグナルハンドラによって割り込まれた後で 自動的に再スタートすることは決してない。)
172 .PP
173 正常に終了した場合、メッセージ・キューのデータ構造体は以下のように 更新される:
174 .IP
175 \fImsg_lrpid\fP には呼び出し元プロセスのプロセス ID が設定される。
176 .IP
177 \fImsg_qnum\fP は 1 減算される。
178 .IP
179 \fImsg_rtime\fP には現在の時刻が設定される。
180 .SH 返り値
181 失敗した場合は、どちらの関数も \-1 を返し、エラーを \fIerrno\fP に表示する。成功した場合、 \fBmsgsnd\fP()  は 0 を返し、
182 \fBmsgrcv\fP()  は \fImtext\fP 配列に実際にコピーしたバイト数を返す。
183 .SH エラー
184 \fBmsgsnd\fP()  が失敗した場合、 \fBerrno\fP に以下の値のいずれかが設定される:
185 .TP 
186 \fBEACCES\fP
187 呼び出し元プロセスにはメッセージ・キューに対する書き込み許可がなく、 \fBCAP_IPC_OWNER\fP ケーパビリティもない。
188 .TP 
189 \fBEAGAIN\fP
190 \fImsg_qbytes\fP がキューの制限を超えていたため、メッセージを送ることができず、かつ \fImsgflg\fP に \fBIPC_NOWAIT\fP
191 が指定されていた。
192 .TP 
193 \fBEFAULT\fP
194 \fImsgp\fP が指しているアドレスがアクセス可能でない。
195 .TP 
196 \fBEIDRM\fP
197 メッセージ・キューが削除された。
198 .TP 
199 \fBEINTR\fP
200 メッセージ・キューが要求した条件を満たすまで停止している時に、 プロセスがシグナルを捕獲した。
201 .TP 
202 \fBEINVAL\fP
203 \fImsqid\fP が不適切な値であるか、 \fImtype\fP が正の値でないか、 \fImsgsz\fP が不適切な値 (0 以下か、システムで決まる値
204 \fBMSGMAX\fP よりも大きい値) である。
205 .TP 
206 \fBENOMEM\fP
207 \fImsgp\fP が指すメッセージのコピーを作成するのに十分なメモリがシステムに存在しない。
208 .PP
209 \fBmsgrcv\fP()  が失敗した場合には \fIerrno\fP に以下の値のいずれかが設定される:
210 .TP 
211 \fBE2BIG\fP
212 メッセージのテキストの長さが \fImsgsz\fP よりも大きく、 \fImsgflg\fP に \fBMSG_NOERROR\fP が設定されていなかった。
213 .TP 
214 \fBEACCES\fP
215 呼び出し元プロセスにはメッセージ・キューに対する読み込み許可がなく、 \fBCAP_IPC_OWNER\fP ケーパビリティもない。
216 .TP 
217 \fBEAGAIN\fP
218 キューにはメッセージがなく、 \fImsgflg\fP に \fBIPC_NOWAIT\fP が指定された。
219 .TP 
220 \fBEFAULT\fP
221 \fImsgp\fP が指しているアドレスがアクセス可能でない。
222 .TP 
223 \fBEIDRM\fP
224 メッセージを受信するためにプロセスが停止している間に、 メッセージ・キューが削除された。
225 .TP 
226 \fBEINTR\fP
227 メッセージを受けるためにプロセスが停止している間に、 プロセスがシグナルを捕獲した。 \fBsignal\fP(7)  参照。
228 .TP 
229 \fBEINVAL\fP
230 \fImsgqid\fP が不正か、 \fImsgsz\fP が 0 より小さい。
231 .TP 
232 \fBEINVAL\fP (Linux 3.14 以降)
233 \fImsgflg\fP specified \fBMSG_COPY\fP, but not \fBIPC_NOWAIT\fP.
234 .TP 
235 \fBEINVAL\fP (Linux 3.14 以降)
236 \fImsgflg\fP specified both \fBMSG_COPY\fP and \fBMSG_EXCEPT\fP.
237 .TP 
238 \fBENOMSG\fP
239 \fImsgflg\fP に \fBIPC_NOWAIT\fP が設定されており、 メッセージ・キューに要求された型のメッセージが存在しなかった。
240 .TP 
241 \fBENOMSG\fP
242 \fBIPC_NOWAIT\fP and \fBMSG_COPY\fP were specified in \fImsgflg\fP and the queue
243 contains less than \fImsgtyp\fP messages.
244 .TP 
245 \fBENOSYS\fP (Linux 3.8 以降)
246 \fIMSG_COPY\fP was specified in \fImsgflg\fP, and this kernel was configured
247 without \fBCONFIG_CHECKPOINT_RESTORE\fP.
248 .SH 準拠
249 SVr4, POSIX.1\-2001.
250
251 .\" MSG_COPY since glibc 2.18
252 The \fBMSG_EXCEPT\fP and \fBMSG_COPY\fP flags are Linux\-specific; their
253 definitions can be obtained by defining the \fB_GNU_SOURCE\fP feature test
254 macro.
255 .SH 注意
256 .\" Like Linux, the FreeBSD man pages still document
257 .\" the inclusion of these header files.
258 Linux や POSIX の全てのバージョンでは、 \fI<sys/types.h>\fP と \fI<sys/ipc.h>\fP
259 のインクルードは必要ない。しかしながら、いくつかの古い実装ではこれらのヘッダファイルのインクルードが必要であり、 SVID
260 でもこれらのインクルードをするように記載されている。このような古いシステムへの移植性を意図したアプリケーションではこれらのファイルをインクルードする必要があるかもしれない。
261
262 \fImsgp\fP 引き数は、 libc4, libc5, glibc 2.0, glibc 2.1 では \fIstruct msgbuf *\fP
263 と宣言されている。glibc 2.2 以降では、 SUSv2 と SUSv3 の要求通り、\fIvoid *\fP と宣言されている。
264
265 以下は \fBmsgsnd\fP システムコールに影響するシステム制限である:
266 .TP 
267 \fBMSGMAX\fP
268 メッセージのテキストの最大サイズ: 8192 バイト (Linux では、この制限値は \fI/proc/sys/kernel/msgmax\fP
269 経由で読み出したり変更したりできる)。
270 .TP 
271 \fBMSGMNB\fP
272 バイト単位でのメッセージ・キューのデフォルトの最大サイズ : 16384 バイト。 (Linux では、この制限値は
273 \fI/proc/sys/kernel/msgmnb\fP 経由で読み出したり変更したりできる)。 スーパーユーザーは \fBmsgctl\fP(2)
274 システムコールでメッセージ・キューのサイズを \fBMSGMNB\fP よりも大きい値に増やすことができる。
275 .PP
276 現在の実装では、システム全体のメッセージ・ヘッダーの最大数 (\fBMSGTQL\fP)  と、システム全体のメッセージ・プールの最大バイト数
277 (\fBMSGPOOL\fP)  に関して実装依存の制限はない。
278 .SH バグ
279 .\" FIXME http://marc.info/?l=linux-kernel&m=139048542803605&w=2
280 .\" commit 4f87dac386cc43d5525da7a939d4b4e7edbea22c
281 In Linux 3.13 and earlier, if \fBmsgrcv\fP()  was called with the \fBMSG_COPY\fP
282 flag, but without \fBIPC_NOWAIT\fP, and the message queue contained less than
283 \fImsgtyp\fP messages, then the call would block until the next message is
284 written to the queue.  At that point, the call would return a copy of the
285 message, \fIregardless\fP of whether that message was at the ordinal position
286 \fImsgtyp\fP.  This bug is fixed in Linux 3.14.
287
288 .\" FIXME http://marc.info/?l=linux-kernel&m=139048542803605&w=2
289 .\" commit 4f87dac386cc43d5525da7a939d4b4e7edbea22c
290 Specifying both \fBMSG_COPY\fP and \fBMSC_EXCEPT\fP in \fImsgflg\fP is a logical
291 error (since these flags impose different interpretations on \fImsgtyp\fP).  In
292 Linux 3.13 and earlier, this error was not diagnosed by \fBmsgrcv\fP().  This
293 bug is fixed in Linux 3.14.
294 .SH 関連項目
295 \fBmsgctl\fP(2), \fBmsgget\fP(2), \fBcapabilities\fP(7), \fBmq_overview\fP(7),
296 \fBsvipc\fP(7)
297 .SH この文書について
298 この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.63 の一部
299 である。プロジェクトの説明とバグ報告に関する情報は
300 http://www.kernel.org/doc/man\-pages/ に書かれている。