OSDN Git Service

935fc2d42dac5737654e9269b98733b596e7aaf2
[linuxjm/LDP_man-pages.git] / draft / man2 / shmop.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 Sun Nov 28 17:06:19 1993, Rik Faith (faith@cs.unc.edu)
26 .\"          with material from Luigi P. Bai (lpb@softint.com)
27 .\" Portions Copyright 1993 Luigi P. Bai
28 .\" Modified Tue Oct 22 22:04:23 1996 by Eric S. Raymond <esr@thyrsus.com>
29 .\" Modified, 5 Jan 2002, Michael Kerrisk <mtk.manpages@gmail.com>
30 .\" Modified, 19 Sep 2002, Michael Kerrisk <mtk.manpages@gmail.com>
31 .\"     Added SHM_REMAP flag description
32 .\" Modified, 27 May 2004, Michael Kerrisk <mtk.manpages@gmail.com>
33 .\"     Added notes on capability requirements
34 .\" Modified, 11 Nov 2004, Michael Kerrisk <mtk.manpages@gmail.com>
35 .\"     Language and formatting clean-ups
36 .\"     Changed wording and placement of sentence regarding attachment
37 .\"             of segments marked for destruction
38 .\"
39 .\" FIXME . Add an example program to this page.
40 .\"
41 .\"*******************************************************************
42 .\"
43 .\" This file was generated with po4a. Translate the source file.
44 .\"
45 .\"*******************************************************************
46 .\"
47 .\" Japanese Version Copyright (c) 1997 HANATAKA Shinya
48 .\"         all rights reserved.
49 .\" Translated 1999-08-15, HANATAKA Shinya <hanataka@abyss.rim.or.jp>
50 .\" Updated & Modified 2002-05-07, Yuichi SATO <ysato@h4.dion.ne.jp>
51 .\" Updated & Modified 2003-01-18, Yuichi SATO <ysato444@yahoo.co.jp>
52 .\" Updated & Modified 2005-01-07, Yuichi SATO
53 .\" Updated 2005-12-05, Akihiro MOTOKI, Catch up to LDP man-pages 2.16
54 .\" Updated 2006-04-14, Akihiro MOTOKI, Catch up to LDP man-pages 2.29
55 .\" Updated 2013-03-26, Akihiro MOTOKI <amotoki@gmail.com>
56 .\" Updated 2013-05-01, Akihiro MOTOKI <amotoki@gmail.com>
57 .\" Updated 2013-07-24, Akihiro MOTOKI <amotoki@gmail.com>
58 .\"
59 .TH SHMOP 2 2014\-04\-28 Linux "Linux Programmer's Manual"
60 .SH 名前
61 shmat, shmdt \- System V 共有メモリ (shared memory) の操作
62 .SH 書式
63 .nf
64 \fB#include <sys/types.h>\fP
65 \fB#include <sys/shm.h>\fP
66
67 \fBvoid *shmat(int \fP\fIshmid\fP\fB, const void *\fP\fIshmaddr\fP\fB, int \fP\fIshmflg\fP\fB);\fP
68
69 \fBint shmdt(const void *\fP\fIshmaddr\fP\fB);\fP
70 .fi
71 .SH 説明
72 .SS shmat()
73 \fBshmat\fP()  は \fIshmid\fP で指定された System\ V 共有メモリ・セグメント (shared memory segment)
74 を コールしたプロセスのアドレス空間に付加 (attach) する。 付加するアドレスは \fIshmaddr\fP に以下のどれかの形式で指定する:
75 .IP * 3
76 \fIshmaddr\fP が NULL ならば、システムはセグメントを付加するための 適切な (使用されていない) アドレスを選択する。
77 .IP *
78 \fIshmaddr\fP が NULL でなく \fBSHM_RND\fP が \fIshmflg\fP に指定されている場合は、 \fIshmaddr\fP を
79 \fBSHMLBA\fP の倍数へと切り捨てた (rounding down) のと等しいアドレスへ付加する。
80 .IP *
81 その他の場合は \fIshmaddr\fP は付加を行なうアドレスで、ページ境界を指している必要がある。
82 .PP
83 In addition to \fBSHM_RND\fP, the following flags may be specified in the
84 \fIshmflg\fP bit\-mask argument:
85 .TP 
86 \fBSHM_EXEC\fP (Linux\-specific; since Linux 2.6.9)
87 Allow the contents of the segment to be executed.  The caller must have
88 execute permission on the segment.
89 .TP 
90 \fBSHM_RDONLY\fP
91 Attach the segment for read\-only access.  The process must have read
92 permission for the segment.  If this flag is not specified, the segment is
93 attached for read and write access, and the process must have read and write
94 permission for the segment.  There is no notion of a write\-only shared
95 memory segment.
96 .TP 
97 \fBSHM_REMAP\fP (Linux\-specific)
98 This flag specifies that the mapping of the segment should replace any
99 existing mapping in the range starting at \fIshmaddr\fP and continuing for the
100 size of the segment.  (Normally, an \fBEINVAL\fP error would result if a
101 mapping already exists in this address range.)  In this case, \fIshmaddr\fP
102 must not be NULL.
103 .PP
104 呼び出したプロセスの \fBbrk\fP(2)  の値は付加によって変化しない。 そのセグメントはプロセスが終了 (exit) したら自動的に分離
105 (detach) される。 同じセグメントをプロセスのアドレス空間に、読み込み専用および読み書き両用 として付加でき、また複数回付加することもできる。
106 .PP
107 成功した \fBshmat\fP()  コールは共有メモリ・セグメントに関連する \fIshmid_ds\fP 構造体 (\fBshmctl\fP(2)  を参照)
108 のメンバーを以下のように更新する:
109 .IP
110 \fIshm_atime\fP には現在の時刻を設定する。
111 .IP
112 \fIshm_lpid\fP には呼び出したプロセスのプロセス ID が設定される。
113 .IP
114 .\"
115 \fIshm_nattch\fP を 1 増加させる。
116 .SS shmdt()
117 \fBshmdt\fP()  は呼び出したプロセスのアドレス空間から \fIshmaddr\fP で指定されたアドレスに配置された共有メモリ・セグメントを分離
118 (detach) する。 分離する共有メモリ・セグメントは、現在 \fIshmaddr\fP に付加されているものでなければならない。 \fIshmaddr\fP
119 は、それを付加した時に \fBshmat\fP()  が返した値に等しくなければならない。
120 .PP
121 成功した \fBshmdt\fP()  コールはその共有メモリ・セグメントに関連する \fIshmid_ds\fP 構造体のメンバーを以下のように更新する:
122 .IP
123 \fIshm_dtime\fP には現在の時刻が設定される。
124 .IP
125 \fIshm_lpid\fP には呼び出したプロセスのプロセス ID が設定される。
126 .IP
127 \fIshm_nattch\fP を 1 減少させる。 もし 0 になり、削除マークがあった場合は そのセグメントは削除される。
128 .SH 返り値
129 \fBshmat\fP()  は、成功した場合、 付加された共有メモリ・セグメントのアドレスを返す。 エラーの場合、 \fI(void\ *)\ \-1\fP
130 を返し、 \fIerrno\fP にエラーの原因を示す値を設定する。
131
132 \fBshmdt\fP()  は、成功すると 0 を返す。 エラーの場合、\-1 を返し、 \fIerrno\fP にエラーの原因を示す値を設定する。
133 .SH エラー
134 \fBshmat\fP()  が失敗した場合、 \fIerrno\fP に以下の値のどれかを設定して返す:
135 .TP 
136 \fBEACCES\fP
137 呼び出したプロセスに要求された種類の付加に必要な許可がなく、 \fBCAP_IPC_OWNER\fP ケーパビリティ (capability) がない。
138 .TP 
139 \fBEIDRM\fP
140 \fIshmid\fP が削除 (remove) された識別子 (identifier) を指している。
141 .TP 
142 \fBEINVAL\fP
143 \fIshmid\fP の値が不正である。 \fIshmaddr\fP の値が境界違反 (unaligned) (つまり、ページ境界に合っておらず、
144 \fBSHM_RND\fP が指定されていない) または が不正である。 \fIshmaddr\fP へのセグメントの付加に失敗した。 または
145 \fBSHM_REMAP\fP が指定されているが、 \fIshmaddr\fP が NULL であった。
146 .TP 
147 \fBENOMEM\fP
148 ディスクリプター (descriptor) やページ・テーブルのためのメモリを 割り当てることができない。
149 .PP
150 \fBshmdt\fP()  が失敗した場合、 \fBEINVAL\fP は以下のようにセットされる:
151 .TP 
152 \fBEINVAL\fP
153 .\" The following since 2.6.17-rc1:
154 \fIshmaddr\fP に付加された共有メモリ・セグメントが存在しない。 もしくは、 \fIshmaddr\fP がページ境界に合っていない。
155 .SH 準拠
156 .\" SVr4 documents an additional error condition EMFILE.
157 SVr4, POSIX.1\-2001.
158
159 SVID 3 で (たぶんそれより前だと思うが)  \fIshmaddr\fP 引き数の型は \fIchar\ *\fP から \fIconst void\ *\fP
160 に、\fIshmat\fP() の返り値の型は \fIchar\ *\fP から \fIvoid\ *\fP に変更された (Linux では libc4 と libc5
161 のプロトタイプは \fIchar\ *\fP であり、glibc2 のプロトタイプは \fIvoid\ *\fP である)。
162 .SH 注意
163 .PP
164 \fBfork\fP(2)  した後、子プロセスは付加された共有メモリ・セグメントを継承する。
165
166 \fBexec\fP(2)  した後、全ての付加された共有メモリ・セグメントはプロセスから分離される。
167
168 \fBexit\fP(2)  において、全ての付加された共有メモリ・セグメントはプロセスから分離される。
169
170 共有メモリセグメントを付加する場合の移植性の高い方法としては、 \fIshmaddr\fP を NULL にして \fBshmat\fP()  を使用するのがよい。
171 このような方法で付加される共有メモリセグメントは、 プロセスが異なれば別のアドレスに付加される、という点に注意すること。
172 よって共有メモリ内で管理されるポインタは、 絶対アドレスではなく、 (一般的にはセグメントの開始アドレスからの)  相対アドレスで作成するべきである。
173 .PP
174 Linux では共有メモリセグメントに既に削除マークが付けられていても、 その共有メモリセグメントを付加することができる。 しかし
175 POSIX.1\-2001 ではこのような動作を指定しておらず、 他の多くの実装もこれをサポートしていない。
176 .LP
177 以下のシステム・パラメーターは、 \fBshmat\fP()  に影響する:
178 .TP 
179 .\" FIXME A good explanation of the rationale for the existence
180 .\" of SHMLBA would be useful here
181 \fBSHMLBA\fP
182 .\" FIXME That last sentence isn't true for all Linux
183 .\" architectures (i.e., SHMLBA != PAGE_SIZE for some architectures)
184 .\" -- MTK, Nov 04
185 セグメントの境界アドレスの最小倍数。ページ境界に合ってなければならない。 現在の実装では \fBSHMLBA\fP の値は \fBPAGE_SIZE\fP である。
186 .PP
187 The implementation places no intrinsic per\-process limit on the number of
188 shared memory segments (\fBSHMSEG\fP).
189 .SH 関連項目
190 \fBbrk\fP(2), \fBmmap\fP(2), \fBshmctl\fP(2), \fBshmget\fP(2), \fBcapabilities\fP(7),
191 \fBshm_overview\fP(7), \fBsvipc\fP(7)
192 .SH この文書について
193 この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.67 の一部
194 である。プロジェクトの説明とバグ報告に関する情報は
195 http://www.kernel.org/doc/man\-pages/ に書かれている。