OSDN Git Service

(split) LDP: Restore and add Copyrights for draft pages
[linuxjm/LDP_man-pages.git] / draft / man2 / shmget.2
1 .\" Copyright (c) 1993 Luigi P. Bai (lpb@softint.com) July 28, 1993
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 Wed Jul 28 10:57:35 1993, Rik Faith <faith@cs.unc.edu>
26 .\" Modified Sun Nov 28 16:43:30 1993, Rik Faith <faith@cs.unc.edu>
27 .\"          with material from Giorgio Ciucci <giorgio@crcc.it>
28 .\" Portions Copyright 1993 Giorgio Ciucci <giorgio@crcc.it>
29 .\" Modified Tue Oct 22 22:03:17 1996 by Eric S. Raymond <esr@thyrsus.com>
30 .\" Modified, 8 Jan 2003, Michael Kerrisk, <mtk.manpages@gmail.com>
31 .\"     Removed EIDRM from errors - that can't happen...
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 .\"     Added notes on /proc files
37 .\"
38 .\"*******************************************************************
39 .\"
40 .\" This file was generated with po4a. Translate the source file.
41 .\"
42 .\"*******************************************************************
43 .\"
44 .\" Japanese Version Copyright (c) 1997 HANATAKA Shinya
45 .\"         all rights reserved.
46 .\" Translated 1997-03-01, HANATAKA Shinya <hanataka@abyss.rim.or.jp>
47 .\" Updated & Modified 2001-06-03, Yuichi SATO <ysato@h4.dion.ne.jp>
48 .\" Updated 2001-12-22, Kentaro Shirakata <argrath@ub32.org>
49 .\" Updated 2002-10-16, Kentaro Shirakata <argrath@ub32.org>
50 .\" Updated 2003-02-23, Kentaro Shirakata <argrath@ub32.org>
51 .\" Updated 2005-03-02, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
52 .\" Updated 2005-11-04, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
53 .\" Updated 2006-07-21, Akihiro MOTOKI, LDP v2.36
54 .\" Updated 2013-05-06, Akihiro MOTOKI <amotoki@gmail.com>
55 .\" Updated 2013-07-24, Akihiro MOTOKI <amotoki@gmail.com>
56 .\"
57 .TH SHMGET 2 2013\-04\-19 Linux "Linux Programmer's Manual"
58 .SH 名前
59 shmget \- System V 共有メモリ・セグメントを割り当てる
60 .SH 書式
61 .ad l
62 \fB#include <sys/ipc.h>\fP
63 .br
64 \fB#include <sys/shm.h>\fP
65 .sp
66 \fBint shmget(key_t \fP\fIkey\fP\fB, size_t \fP\fIsize\fP\fB, int \fP\fIshmflg\fP\fB);\fP
67 .ad b
68 .SH 説明
69 \fBshmget\fP()  は \fIkey\fP 引き数に対応する System V 共有メモリ・セグメントの識別子を返す。 \fIkey\fP の値が
70 \fBIPC_PRIVATE\fP の場合、もしくは \fIkey\fP に対応する共有メモリ・セグメントが存在せず、 \fIshmflg\fP に
71 \fBIPC_CREAT\fP が指定されていた場合、 新しい共有メモリ・セグメントを作成する。 作成される共有メモリ・セグメントは、 \fIsize\fP
72 引き数の値を \fBPAGE_SIZE\fP の倍数へと切り上げた (round up) 大きさとなる。
73 .PP
74 \fIshmflg\fP に \fBIPC_CREAT\fP と \fBIPC_EXCL\fP の両方が指定された場合、 \fIkey\fP
75 に対応する共有メモリ・セグメントが既に存在すると、 \fBshmget\fP()  は失敗し、 \fIerrno\fP に \fBEEXIST\fP が設定される
76 (これは \fBopen\fP(2)  に \fBO_CREAT | O_EXCL\fP を指定した場合の動作と同じである)。
77 .PP
78 \fIshmflg\fP は以下の内容から構成される:
79 .TP  12
80 \fBIPC_CREAT\fP
81 新しいセグメントを作成する。このフラグが指定されなかった場合、 \fBshmget\fP()  は \fIkey\fP に対応するセグメントを探し、
82 ユーザがそのセグメントにアクセスする許可があるかどうかをチェックする。
83 .TP 
84 \fBIPC_EXCL\fP
85 \fBIPC_CREAT\fP と共に使用し、セグメントが既に存在した場合には 失敗することを保証する。
86 .TP 
87 \fImode_flags\fP
88 (下位 9 ビット)  所有者、グループ、他人 (world) への許可を指定する。 これらのビットは \fBopen\fP(2)  の \fImode\fP
89 引き数と同じ形式で同じ意味を持つ。 今のところ、システムは実行 (execute) 許可を参照しない。
90 .TP 
91 \fBSHM_HUGETLB\fP (Linux 2.6 以降)
92 "ヒュージページ (huge page)" を使うセグメントを割り当てる。詳細な情報は、Linux カーネルソースのファイル
93 \fIDocumentation/vm/hugetlbpage.txt\fP を参照。
94 .TP 
95 \fBSHM_NORESERVE\fP (Linux 2.6.15 以降)
96 .\" As at 2.6.17-rc2, this flag has no effect if SHM_HUGETLB was also
97 .\" specified.
98 このフラグは、 \fBmmap\fP(2)  の \fBMAP_NORESERVE\fP フラグと同じ役割を果たす。
99 このセグメントに対するスワップ空間の予約を行わない。 スワップ空間を予約した場合は、そのセグメントの変更が必ず成功することが
100 保証される。スワップ空間の予約を行わなかった場合は、物理メモリに空きが ないと書き込み時に \fBSIGSEGV\fP を受け取る可能性がある。
101 \fBproc\fP(5)  にある \fI/proc/sys/vm/overcommit_memory\fP ファイルに関する議論も参照のこと。
102 .PP
103 共有メモリ・セグメントが新たに作成される際、 共有メモリ・セグメントの内容は 0 で初期化され、 関連情報を保持するデータ構造体 \fIshmid_ds\fP
104 は以下のように初期化される。
105 .IP
106 \fIshm_perm.cuid\fP と \fIshm_perm.uid\fP に呼び出し元プロセスの実効 (effective) ユーザーID を設定する。
107 .IP
108 \fIshm_perm.cgid\fP と \fIshm_perm.gid\fP に呼び出し元プロセスの実効グループID を設定する。
109 .IP
110 \fIshm_perm.mode\fP の下位 9 ビットに \fIshmflg\fP の下位 9 ビットを設定する。
111 .IP
112 \fIshm_segsz\fP に \fIsize\fP の値を設定する。
113 .IP
114 \fIshm_lpid\fP, \fIshm_nattch\fP, \fIshm_atime\fP, \fIshm_dtime\fP に 0 を設定する。
115 .IP
116 \fIshm_ctime\fP に現在の時刻を設定する。
117 .PP
118 共有メモリ・セグメントが既に存在する場合、アクセス許可の検査と、 破壊 (destruction) マークがつけられていないかのチェックが行われる。
119 .SH 返り値
120 成功の場合、有効な共有メモリ・セグメントの識別子が返される。 エラーの場合、 \-1 が返り、 \fIerror\fP にエラーを示す値が設定される。
121 .SH エラー
122 失敗した場合は \fIerrno\fP が以下のどれかに設定される:
123 .TP 
124 \fBEACCES\fP
125 ユーザーはその共有メモリ・セグメントへのアクセス許可を持たず、 \fBCAP_IPC_OWNER\fP ケーパビリティも持っていない。
126 .TP 
127 \fBEEXIST\fP
128 \fBIPC_CREAT | IPC_EXCL\fP が指定されていたが、そのセグメントが既に存在する。
129 .TP 
130 \fBEINVAL\fP
131 新しいセグメントを作成しようとした際に \fIsize\fP < \fBSHMMIN\fP または \fIsize\fP > \fBSHMMAX\fP
132 であった。 もしくは、指定されたキーに対応するセグメントが既に存在して、新しい セグメントを作成しようとはしなかったが、\fIsize\fP
133 が存在するセグメントの サイズよりも大きかった。
134 .TP 
135 \fBENFILE\fP
136 .\" [2.6.7] shmem_zero_setup()-->shmem_file_setup()-->get_empty_filp()
137 システム全体でオープンされているファイルの総数が上限に達した。
138 .TP 
139 \fBENOENT\fP
140 指定された \fIkey\fP に対応するセグメントが存在せず、 \fBIPC_CREAT\fP も指定されていなかった。
141 .TP 
142 \fBENOMEM\fP
143 セグメントの管理情報 (overhead) に割り当てるメモリがなかった。
144 .TP 
145 \fBENOSPC\fP
146 システム全体の共有メモリ・セグメント数の制限 (\fBSHMMNI\fP)  に達した、または要求された \fIsize\fP のセグメントの割り当てが
147 システム全体の共有メモリサイズの制限 (\fBSHMALL\fP)  を超過した。
148 .TP 
149 \fBEPERM\fP
150 \fBSHM_HUGETLB\fP フラグが指定されたが、呼び出し元には権限がなかった (\fBCAP_IPC_LOCK\fP ケーパビリティを持っていなかった)。
151 .SH 準拠
152 .\" SVr4 documents an additional error condition EEXIST.
153 SVr4, POSIX.1\-2001.
154
155 \fBSHM_HUGETLB\fP は Linux での拡張であり、移植性はない。
156 .SH 注意
157 .\" Like Linux, the FreeBSD man pages still document
158 .\" the inclusion of these header files.
159 Linux や POSIX の全てのバージョンでは、 \fI<sys/types.h>\fP と \fI<sys/ipc.h>\fP
160 のインクルードは必要ない。しかしながら、いくつかの古い実装ではこれらのヘッダファイルのインクルードが必要であり、 SVID
161 でもこれらのインクルードをするように記載されている。このような古いシステムへの移植性を意図したアプリケーションではこれらのファイルをインクルードする必要があるかもしれない。
162
163 \fBIPC_PRIVATE\fP はフラグではなく \fIkey_t\fP 型である。 この特別な値が \fIkey\fP に使用された場合は、 \fBshmget\fP()
164 は \fIshmflg\fP の下位 9 ビットを除いた全てを無視し、 (成功すれば) 新しい共有メモリ・セグメントを作成する。
165 .PP
166 \fBshmget\fP()  コールに影響する共有メモリ・セグメント資源の制限は以下の通りである:
167 .TP 
168 \fBSHMALL\fP
169 システム全体の共有メモリ・ページの最大数 (Linux では、この上限値は \fI/proc/sys/kernel/shmall\fP
170 経由で参照したり、変更したりできる)。
171 .TP 
172 \fBSHMMAX\fP
173 共有メモリ・セグメントのバイト単位の大きさの上限: 方針依存 (Linux では、この上限値は \fI/proc/sys/kernel/shmmax\fP
174 経由で参照したり、変更したりできる)。
175 .TP 
176 \fBSHMMIN\fP
177 共有メモリ・セグメントのバイト単位の大きさの下限: 実装依存 (現在は 1 バイトだが、実質的な最小サイズは \fBPAGE_SIZE\fP である)。
178 .TP 
179 \fBSHMMNI\fP
180 .\" Kernels between 2.4.x and 2.6.8 had an off-by-one error that meant
181 .\" that we could create one more segment than SHMMNI -- MTK
182 .\" This /proc file is not available in Linux 2.2 and earlier -- MTK
183 システム全体の共有メモリーの数の上限: 実装依存 (現在は 4096。Linux 2.3.99 より前では 128。 Linux では、この上限値は
184 \fI/proc/sys/kernel/shmmni\fP 経由で参照したり、変更したりできる)。
185 .PP
186 プロセス当りの共有メモリ・セグメントの個数の最大値 (\fBSHMSEG\fP)  に関する実装上の制限はない。
187 .SS "Linux での注意"
188 バージョン 2.3.30 までは、Linux は 削除が予定されている共有メモリ・セグメントに対して \fBshmget\fP()  が行われると
189 \fBEIDRM\fP を返していた。
190 .SH バグ
191 \fBIPC_PRIVATE\fP という名前を選んだのはおそらく失敗であろう。 \fBIPC_NEW\fP の方がより明確にその機能を表しているだろう。
192 .SH 関連項目
193 \fBshmat\fP(2), \fBshmctl\fP(2), \fBshmdt\fP(2), \fBftok\fP(3), \fBcapabilities\fP(7),
194 \fBshm_overview\fP(7), \fBsvipc\fP(7)
195 .SH この文書について
196 この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.53 の一部
197 である。プロジェクトの説明とバグ報告に関する情報は
198 http://www.kernel.org/doc/man\-pages/ に書かれている。