OSDN Git Service

(split) DP: release pages (catch up to 3.50).
[linuxjm/LDP_man-pages.git] / release / man2 / shmctl.2
1 .\" Copyright (c) 1993 Luigi P. Bai (lpb@softint.com) July 28, 1993
2 .\" and Copyright 1993 Giorgio Ciucci <giorgio@crcc.it>
3 .\" and Copyright 2004, 2005 Michael Kerrisk <mtk.manpages@gmail.com>
4 .\"
5 .\" %%%LICENSE_START(VERBATIM)
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 .\" %%%LICENSE_END
26 .\"
27 .\" Modified 1993-07-28, Rik Faith <faith@cs.unc.edu>
28 .\" Modified 1993-11-28, Giorgio Ciucci <giorgio@crcc.it>
29 .\" Modified 1997-01-31, Eric S. Raymond <esr@thyrsus.com>
30 .\" Modified 2001-02-18, Andries Brouwer <aeb@cwi.nl>
31 .\" Modified 2002-01-05, 2004-05-27, 2004-06-17,
32 .\"    Michael Kerrisk <mtk.manpages@gmail.com>
33 .\" Modified 2004-10-11, aeb
34 .\" Modified, Nov 2004, Michael Kerrisk <mtk.manpages@gmail.com>
35 .\"     Language and formatting clean-ups
36 .\"     Updated shmid_ds structure definitions
37 .\"     Added information on SHM_DEST and SHM_LOCKED flags
38 .\"     Noted that CAP_IPC_LOCK is not required for SHM_UNLOCK
39 .\"             since kernel 2.6.9
40 .\" Modified, 2004-11-25, mtk, notes on 2.6.9 RLIMIT_MEMLOCK changes
41 .\" 2005-04-25, mtk -- noted aberrant Linux behavior w.r.t. new
42 .\"     attaches to a segment that has already been marked for deletion.
43 .\" 2005-08-02, mtk: Added IPC_INFO, SHM_INFO, SHM_STAT descriptions.
44 .\"
45 .\"*******************************************************************
46 .\"
47 .\" This file was generated with po4a. Translate the source file.
48 .\"
49 .\"*******************************************************************
50 .TH SHMCTL 2 2012\-05\-31 Linux "Linux Programmer's Manual"
51 .SH 名前
52 shmctl \- 共有メモリ (shared memory) を制御する
53 .SH 書式
54 .ad l
55 \fB#include <sys/ipc.h>\fP
56 .br
57 \fB#include <sys/shm.h>\fP
58 .sp
59 \fBint shmctl(int \fP\fIshmid\fP\fB, int \fP\fIcmd\fP\fB, struct shmid_ds *\fP\fIbuf\fP\fB);\fP
60 .ad b
61 .SH 説明
62 \fBshmctl\fP()  は、識別子が \fIshmid\fP の共有メモリ・セグメントに対して \fIcmd\fP で指示した制御命令を実行する。
63 .PP
64 \fIbuf\fP 引き数は、 \fIshmid_ds\fP 構造体へのポインタである。 この構造体は \fI<sys/shm.h>\fP
65 で以下のように定義されている
66 .PP
67 .in +4n
68 .nf
69 struct shmid_ds {
70     struct ipc_perm shm_perm;    /* 所有権と許可 */
71     size_t          shm_segsz;   /* セグメントのサイズ (バイト) */
72     time_t          shm_atime;   /* 最後の付加 (attach) の時刻 */
73     time_t          shm_dtime;   /* 最後の分離 (detach) の時刻 */
74     time_t          shm_ctime;   /* 最後に変更が行われた時刻 */
75     pid_t           shm_cpid;    /* 作成者 (creator) の PID */
76     pid_t           shm_lpid;    /* 最後の shmat(2)/shmdt(2) の PID */
77     shmatt_t        shm_nattch;  /* 現在付加されている数 */
78     ...
79 };
80 .fi
81 .in
82 .PP
83 The \fIipc_perm\fP structure is defined as follows (the highlighted fields are
84 settable using \fBIPC_SET\fP):
85 .PP
86 .in +4n
87 .nf
88 struct ipc_perm {
89     key_t          __key;    /* shmget(2) に与えられるキー */
90     uid_t          \fBuid\fP;      /* 所有者の実効 UID */
91     gid_t          \fBgid\fP;      /* 所有者の実効 GID */
92     uid_t          cuid;     /* 作成者の実効 UID */
93     gid_t          cgid;     /* 作成者の実効 GID */
94     unsigned short \fBmode\fP;     /* \fB許可\fP + SHM_DEST と
95                                 SHM_LOCKED フラグ */
96     unsigned short __seq;    /* シーケンス番号 */
97 };
98 .fi
99 .in
100 .PP
101 \fIcmd\fP として有効な値は以下の通り:
102 .br
103 .TP  10
104 \fBIPC_STAT\fP
105 \fIshmid\fP に関連づけられたカーネルデータ構造体の情報を \fIbuf\fP で指された \fIshmid_ds\fP 構造体にコピーする。
106 呼び出し元は共有メモリ・セグメントに対する 読み込み許可を持たなければならない。
107 .TP 
108 \fBIPC_SET\fP
109 \fIbuf\fP によって指される \fIshmid_ds\fP 構造体のいくつかのメンバーの値を、
110 この共有メモリ・セグメントに関連づけられたカーネルデータ構造体に書き込み、 \fIshm_ctime\fP メンバーも更新する。
111 以下のフィールドは変更できる。 \fIshm_perm.uid\fP, \fIshm_perm.gid\fP, \fIshm_perm.mode\fP (の最下位 9
112 ビット)。 呼び出したプロセスの実効 UID が所有者 (\fIshm_perm.uid\fP)  または作成者 (\fIshm_perm.cuid\fP)
113 と一致するか、呼び出し元が特権を持たなければならない。
114 .TP 
115 \fBIPC_RMID\fP
116 セグメントに破棄済みのマークを付ける。 セグメントは、実際には最後プロセスがセグメントを分離した (関連する \fIshmid_ds\fP 構造体の
117 \fIshm_nattch\fP メンバーが 0 になった) 後でのみ破棄される。 呼び出し元は所有者か作成者であるか、特権を持たなければならない。
118 セグメントに破棄のマークが付けられると、 関連するデータ構造体において \fIshm_perm.mode\fP フィールドの (標準ではない)
119 \fBSHM_DEST\fP フラグが設定される。 このデータ構造体は \fBIPC_STAT\fP で取得される。
120 .PP
121 呼び出し元は最終的にはセグメントを忘れずに破棄\fIしなければならない\fP。 そうでなれば、フォールト (fault) されたページは メモリかスワップ
122 (swap) に残り続ける。
123 .TP  10
124 \fBIPC_INFO\fP (Linux 固有)
125 システム全体での共有メモリの制限とパラメータに関する情報を、 \fIbuf\fP が指す構造体に入れて返す。 この構造体は \fIshminfo\fP 型である
126 (そのためキャストが必要である)。 \fIshminfo\fP は \fB_GNU_SOURCE\fP 機能検査マクロが定義された場合に
127 \fI<sys/shm.h>\fP で以下のように定義される:
128 .nf
129 .in +4n
130
131 struct  shminfo {
132     unsigned long shmmax; /* 最大セグメントサイズ */
133     unsigned long shmmin; /* 最小セグメントサイズ。
134                              常に 1 */
135     unsigned long shmmni; /* 最大セグメント数 */
136     unsigned long shmseg; /* プロセスが付加できる
137                              セグメントの最大数。
138                              カーネル内では未使用 */
139     unsigned long shmall; /* 共有メモリの最大ページ数。
140                              システム全体での値 */
141 };
142
143 .in
144 .fi
145 設定 \fIshmmni\fP, \fIshmmax\fP, \fIshmall\fP は \fI/proc\fP にある同じ名前のファイル経由で変更可能である。 詳しくは
146 \fBproc\fP(5)  を参照。
147 .TP 
148 \fBSHM_INFO\fP (Linux 固有)
149 共有メモリが消費しているシステム資源に関する情報を 格納した \fIshm_info\fP 構造体を返す。 この構造体は、 \fB_GNU_SOURCE\fP
150 機能検査マクロが定義された場合に \fI<sys/shm.h>\fP で以下のように定義される:
151 .nf
152 .in +4n
153
154 struct shm_info {
155     int           used_ids; /* 現在存在するセグメント数 */
156     unsigned long shm_tot;  /* 共有メモリのページ総数 */
157     unsigned long shm_rss;  /* メモリ上にある (スワップされて
158                                いない) 共有メモリページ数 */
159     unsigned long shm_swp;  /* スワップされている共有メモリ
160                                ページ数 */
161     unsigned long swap_attempts;
162                             /* Linux 2.4 以降では未使用 */
163     unsigned long swap_successes;
164                             /* Linux 2.4 以降では未使用 */
165 };
166 .in
167 .fi
168 .TP 
169 \fBSHM_STAT\fP (Linux 固有)
170 \fBIPC_STAT\fP と同じく \fIshmid_ds\fP 構造体を返す。 但し、 \fIshmid\fP
171 引き数は、セグメント識別子ではなく、システム上の全ての共有メモリ セグメントに関する情報を管理するカーネルの内部配列へのインデックス である。
172 .PP
173 呼び出し元は、\fIcmd\fP に以下の値を指定することで、共有メモリ・セグメントが スワップされることを防止したり、許可したりできる:
174 .br
175 .TP  10
176 \fBSHM_LOCK\fP (Linux 固有)
177 共有メモリ・セグメントをスワップすることを防止する。 ロックが有効になった後、呼び出し元は、
178 存在することが要求された全てのページをフォールトさせなければならない。 セグメントがロックされると、 関連するデータ構造体において
179 \fIshm_perm.mode\fP フィールドの (標準的ではない)  \fBSHM_LOCKED\fP フラグが設定される。 このデータ構造体は
180 \fBIPC_STAT\fP で取得される。
181 .TP 
182 \fBSHM_UNLOCK\fP (Linux 固有)
183 セグメントのロックを解除し、スワップ・アウトすることを可能にする。
184 .PP
185 .\" There was some weirdness in 2.6.9: SHM_LOCK and SHM_UNLOCK could
186 .\" be applied to a segment, regardless of ownership of the segment.
187 .\" This was a botch-up in the move to RLIMIT_MEMLOCK, and was fixed
188 .\" in 2.6.10.  MTK, May 2005
189 2.6.10 より前のカーネルでは、特権プロセスだけが \fBSHM_LOCK\fP と \fBSHM_UNLOCK\fP を利用することができた。 2.6.10
190 以降のカーネルでは、非特権プロセスであっても次の条件を満たせば これらの操作を利用することができる。その条件とは、プロセスの実効 UID
191 がそのセグメントの所有者もしくは作成者の UID と一致し、 (\fBSHM_LOCK\fP の場合には) ロックするメモリの合計が
192 \fBRLIMIT_MEMLOCK\fP リソース上限 (\fBsetrlimit\fP(2)  参照) の範囲内に入っていることである。
193 .SH 返り値
194 \fBIPC_INFO\fP と \fBSHM_INFO\fP 操作は、成功すると、全ての共有メモリセグメントに関する情報を
195 管理しているカーネルの内部配列の使用中エントリのインデックスの うち最大値を返す (この情報は、システムの全ての共有メモリセグメントに関する情報を
196 取得するために、 \fBSHM_STAT\fP 操作を繰り返し実行する際に使用できる)。 \fBSHM_STAT\fP 操作は、成功すると、 \fIshmid\fP
197 で指定されたインデックスを持つ共有メモリセグメントの識別子を返す。 他の操作は、成功の場合 0 を返す。
198
199 エラーの場合は \-1 を返し、 \fIerrno\fP を適切に設定する。
200 .SH エラー
201 .TP 
202 \fBEACCES\fP
203 \fBIPC_STAT\fP または \fBSHM_STAT\fP が要求され、 \fIshm_perm.mode\fP が \fIshmid\fP
204 への読み込みアクセスを許しておらず、 かつ呼び出したプロセスが \fBCAP_IPC_OWNER\fP ケーパビリティ (capability)
205 を持っていない。
206 .TP 
207 \fBEFAULT\fP
208 \fIcmd\fP 引き数に \fBIPC_SET\fP か \fBIPC_STAT\fP が指定されたが \fIbuf\fP で指されているアドレスにアクセスできない。
209 .TP 
210 \fBEIDRM\fP
211 \fIshmid\fP が削除 (remove) された識別子 (identifier) を指している。
212 .TP 
213 \fBEINVAL\fP
214 \fIshmid\fP が有効な識別子でないか、 \fIcmd\fP が有効なコマンドでない。 もしくは、 \fBSHM_STAT\fP 操作の場合に、 \fIshmid\fP
215 で指定されたインデックス値が現在未使用の配列のスロットを参照していた。
216 .TP 
217 \fBENOMEM\fP
218 (2.6.9 以降のカーネルにおいて)  \fBSHM_LOCK\fP が指定され、 ロックされる予定のセグメントのサイズ
219 (ロックされる共有メモリ・セグメントの合計バイト数) が、 呼び出したプロセスの実ユーザー ID についての制限を超えた。 この制限は
220 \fBRLIMIT_MEMLOCK\fP ソフト資源制限で定義される (\fBsetrlimit\fP(2)  を参照)。
221 .TP 
222 \fBEOVERFLOW\fP
223 \fBIPC_STAT\fP が試みられ、GID や UID の値が \fIbuf\fP で指示される構造体に格納するには大き過ぎる。
224 .TP 
225 \fBEPERM\fP
226 \fBIPC_SET\fP か \fBIPC_RMID\fP が試みられ、 呼び出したプロセスの実効ユーザー ID が作成者 (\fIshm_perm.cuid\fP)
227 でも所有者 (\fIshm_perm.uid\fP)  でもなく、プロセスが特権を持たない (Linux では \fBCAP_SYS_ADMIN\fP
228 ケーパビリティを持たない)。
229
230 または (2.6.9 より前のカーネルで)  \fBSHM_LOCK\fP または \fBSHM_UNLOCK\fP が指定されているが、プロセスが特権を持たない
231 (Linux では \fBCAP_IPC_LOCK\fP ケーパビリティを持たない)。 (Linux 2.6.9 以降では、
232 \fBRLIMIT_MEMLOCK\fP が 0 で呼び出し元が特権を持たない場合にも、このエラーが起こる。)
233 .SH 準拠
234 .\" SVr4 documents additional error conditions EINVAL,
235 .\" ENOENT, ENOSPC, ENOMEM, EEXIST.  Neither SVr4 nor SVID documents
236 .\" an EIDRM error condition.
237 SVr4, POSIX.1\-2001.
238 .SH 注意
239 .\" Like Linux, the FreeBSD man pages still document
240 .\" the inclusion of these header files.
241 The inclusion of \fI<sys/types.h>\fP and \fI<sys/ipc.h>\fP isn't
242 required on Linux or by any version of POSIX.  However, some old
243 implementations required the inclusion of these header files, and the SVID
244 also documented their inclusion.  Applications intended to be portable to
245 such old systems may need to include these header files.
246
247 \fBIPC_INFO\fP, \fBSHM_STAT\fP, \fBSHM_INFO\fP 操作は、 \fBipcs\fP(1)
248 プログラムで割り当て済の資源に関する情報を提供するために 使用されている。将来、これらの操作は変更されたり、 /proc
249 ファイルシステムのインタフェースに移動されるかもしれない。
250
251 Linux では、 \fIshmctl(IPC_RMID)\fP を使ってすでに削除マークがつけられている共有メモリ・セグメントを あるプロセスが付加
252 (attach)  (\fBshmat\fP(2))  することを許可している。 この機能は他の UNIX の実装では利用できない。
253 移植性を考慮したアプリケーションではこれに依存しないようにすべきである。
254
255 \fI構造体 shmid_ds\fP 内の多くのフィールドは、 Linux 2.2 では \fIshort\fP 型だったが、Linux 2.4 では
256 \fIlong\fP 型になった。 この利点を生かすには、glibc\-2.1.91 以降の環境下で 再コンパイルすれば十分である。
257 カーネルは新しい形式の呼び出しと古い形式の呼び出しを \fIcmd\fP 内の \fBIPC_64\fP フラグで区別する。
258 .SH 関連項目
259 \fBmlock\fP(2), \fBsetrlimit\fP(2), \fBshmget\fP(2), \fBshmop\fP(2), \fBcapabilities\fP(7),
260 \fBshm_overview\fP(7), \fBsvipc\fP(7)
261 .SH この文書について
262 この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.50 の一部
263 である。プロジェクトの説明とバグ報告に関する情報は
264 http://www.kernel.org/doc/man\-pages/ に書かれている。