OSDN Git Service

(split) LDP: Release pages for LDP v3.39.
[linuxjm/LDP_man-pages.git] / release / man3 / shm_open.3
1 .\" Hey Emacs! This file is -*- nroff -*- source.
2 .\"
3 .\" Copyright (C) 2002 Michael Kerrisk <mtk.manpages@gmail.com>
4 .\"
5 .\" Permission is granted to make and distribute verbatim copies of this
6 .\" manual provided the copyright notice and this permission notice are
7 .\" preserved on all copies.
8 .\"
9 .\" Permission is granted to copy and distribute modified versions of this
10 .\" manual under the conditions for verbatim copying, provided that the
11 .\" entire resulting derived work is distributed under the terms of a
12 .\" permission notice identical to this one.
13 .\"
14 .\" Since the Linux kernel and libraries are constantly changing, this
15 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
16 .\" responsibility for errors or omissions, or for damages resulting from
17 .\" the use of the information contained herein.  The author(s) may not
18 .\" have taken the same level of care in the production of this manual,
19 .\" which is licensed free of charge, as they might when working
20 .\" professionally.
21 .\"
22 .\" Formatted or processed versions of this manual, if unaccompanied by
23 .\" the source, must acknowledge the copyright and authors of this work.
24 .\"
25 .\" FIXME . Add an example to this page
26 .\"*******************************************************************
27 .\"
28 .\" This file was generated with po4a. Translate the source file.
29 .\"
30 .\"*******************************************************************
31 .TH SHM_OPEN 3 2009\-02\-25 Linux "Linux Programmer's Manual"
32 .SH 名前
33 shm_open, shm_unlink \- POSIX 共有メモリ・オブジェクトの作成/オープン、 削除を行う
34 .SH 書式
35 \fB#include <sys/mman.h>\fP
36 .br
37 \fB#include <sys/stat.h>\fP /* mode 定数用 */
38 .br
39 \fB#include <fcntl.h>\fP /* O_* 定数の定義用 */
40 .sp
41 \fBvoid * shm_open(const char *\fP\fIname\fP\fB, int \fP\fIoflag\fP\fB, mode_t
42 \fP\fImode\fP\fB);\fP
43 .sp
44 \fBint shm_unlink(const char *\fP\fIname\fP\fB);\fP
45 .sp
46 \fI\-lrt\fP でリンクする。
47 .SH 説明
48 \fBshm_open\fP()  は、POSIX 共有メモリ・オブジェクトを新規に作成/オープンしたり、 すでに存在するオブジェクトをオープンしたりする。
49 POSIX 共有メモリ・オブジェクトは、実際には、関係のないプロセスが 共有メモリの同じ領域を \fBmmap\fP(2)
50 するために使用することができる手段である。 \fBshm_unlink\fP()  は、逆の操作、つまり以前に \fBshm_open\fP()
51 で作成されたオブジェクトの削除を行う。
52 .LP
53 .\" glibc allows the initial slash to be omitted, and makes
54 .\" multiple initial slashes equivalent to a single slash.
55 .\" This differs from the implementation of POSIX message queues.
56 .\" glibc allows subdirectory components in the name, in which
57 .\" case the subdirectory must exist under /dev/shm, and allow the
58 .\" required permissions if a user wants to create a shared memory
59 .\" object in that subdirectory.
60 \fBshm_open\fP()  の動作は \fBopen\fP(2)  とよく似ている。 \fIname\fP
61 で作成したりオープンしたりする共有メモリ・オブジェクトを指定する。 移植性を持たせるためには、共有メモリ・オブジェクトは \fI/somename\fP
62 という形式の名前で識別し、 その名前は、最大で \fBNAME_MAX\fP (すなわち 255) 文字の NULL 終端された文字列で、
63 スラッシュで始まり、スラッシュ以外の文字が 1 文字以上続く形式 にすべきである。
64 .LP
65 \fIoflag\fP はビットマスクで、 \fBO_RDONLY\fP と \fBO_RDWR\fP のいずれか一方と、以下に述べる他のフラグの論理和をとったもの
66 を指定する。
67 .TP  1.1i
68 \fBO_RDONLY\fP
69 読み出しアクセス用にオブジェクトをオープンする。 このフラグを指定してオープンされた共有メモリ・オブジェクトは、 読み出し (\fBPROT_READ\fP)
70 アクセスでのみ \fBmmap\fP(2)  することができる。
71 .TP 
72 \fBO_RDWR\fP
73 読み書きアクセス用にオブジェクトをオープンする。
74 .TP 
75 \fBO_CREAT\fP
76 .\" In truth it is actually the file system IDs on Linux, but these
77 .\" are nearly always the same as the effective IDs.  (MTK, Jul 05)
78 存在しない場合、共有メモリ・オブジェクトを作成する。 オブジェクトのユーザとグループの所有権は、 呼び出し元プロセスの対応する実効 ID が使われ、
79 オブジェクトの許可ビットは \fImode\fP の下位 9 ビットに基づいて設定される。ただし、 ファイルモード作成マスク (\fBumask\fP(2)
80 参照) に設定されている値は、新規オブジェクトに関してはクリアされる。 \fImode\fP を定義するために使用できるマクロ定数(群)は
81 \fBopen\fP(2)  に記載されている (これらの定数のシンボル定義は \fI<sys/stat.h>\fP
82 のインクルードにより得られる)。
83 .sp
84 新規に作成された共有メモリ・オブジェクトは長さ 0 で初期化される。 オブジェクトの大きさは \fBftruncate\fP(2)  を使って設定できる。
85 共有メモリ・オブジェクトとして新規に確保されたバイトは自動的に 0 に初期化される。
86 .TP 
87 \fBO_EXCL\fP
88 \fBO_CREAT\fP が一緒に指定されており、 \fIname\fP で指定された共有メモリ・オブジェクトが既に存在した場合、 エラーを返す。
89 オブジェクトの存在確認と、存在しなかった場合のオブジェクト作成は、 必ず一連の操作として実行される (performed atomically)。
90 .TP 
91 \fBO_TRUNC\fP
92 共有メモリ・オブジェクトがすでに存在した場合、 そのオブジェクトを 0 バイトに切り詰める。
93 .LP
94 これらのフラグ値の定義は \fI<fcntl.h>\fP のインクルードにより得られる。
95 .LP
96 成功して完了した場合、 \fBshm_open\fP()  は共有メモリ・オブジェクトを参照する新しいファイル・ディスクリプタを返す。
97 このファイル・ディスクリプタは、そのプロセス内で過去にオープンされていない ファイル・ディスクリプタの中で最も小さな数になることが保証される。
98 \fBFD_CLOEXEC\fP フラグ (\fBfcntl\fP(2)  を参照) が、このファイル・ディスクリプタに設定される。
99
100 通常、これらのファイル・ディスクリプタは、この後続けて実行される \fBftruncate\fP(2)  (新規に作成されたオブジェクトの場合のみ) と
101 \fBmmap\fP(2)  の呼び出しに使用される。 \fBmmap\fP(2)  を呼び出した後は、ファイル・ディスクリプタをクローズしてもよく、
102 クローズしてもメモリ・マッピングに影響を与えることはない。
103
104 \fBshm_unlink\fP()  の動作は \fBunlink\fP(2)  とよく似ている:
105 共有メモリ・オブジェクト名を削除し、すべてのプロセスが処理対象の オブジェクトをアンマップした時点でオブジェクトの割り当てを解除し、
106 対応するメモリ領域の内容を破棄する。 \fBshm_unlink\fP()  が成功した後で、同じ \fIname\fP を持つオブジェクトに対して
107 \fBshm_open\fP()  を行うと、 (\fBO_CREAT\fP が指定されていない場合) 失敗する。 (\fBO_CREAT\fP
108 が指定されている場合、新しく別のオブジェクトが作成される)。
109 .SH 返り値
110 成功した場合、 \fBshm_open\fP()  は非負のファイル・ディスクリプタを返す。 失敗した場合、 \fBshm_open\fP()  は \-1 を返す。
111 \fBshm_unlink\fP()  は、成功した場合 0 を、エラーが起こった場合 \-1 を返す。
112 .SH エラー
113 失敗した場合、エラーの原因を示すため \fIerrno\fP が設定される。 \fIerrno\fP に設定される値は以下の通りである:
114 .TP 
115 \fBEACCES\fP
116 共有メモリオブジェクトを \fBshm_unlink\fP()  する権限がなかった。
117 .TP 
118 \fBEACCES\fP
119 指定された \fImode\fP で \fIname\fP を \fBshm_open\fP()  する権限がなかった。もしくは、 \fBO_TRUNC\fP
120 が指定されたが、呼び出し元にはそのオブジェクトに対する書き込み権限が なかった。
121 .TP 
122 \fBEEXIST\fP
123 \fBO_CREAT\fP と \fBO_EXCL\fP の両方が \fBshm_open\fP()  に指定されたが、 \fIname\fP
124 で指定された共有メモリ・オブジェクトが既に存在した。
125 .TP 
126 \fBEINVAL\fP
127 \fBshm_open\fP()  に与えられた \fIname\fP 引き数が不正であった。
128 .TP 
129 \fBEMFILE\fP
130 プロセスがオープン可能なファイル数の上限にすでに達していた。
131 .TP 
132 \fBENAMETOOLONG\fP
133 \fIname\fP の長さが \fBPATH_MAX\fP を越えている。
134 .TP 
135 \fBENFILE\fP
136 ファイルシステムでオープンできるファイル数の上限に達した。
137 .TP 
138 \fBENOENT\fP
139 存在していない \fIname\fP のオブジェクトを \fBshm_open\fP()  しようとしたが、 \fBO_CREAT\fP が指定されていなかった。
140 .TP 
141 \fBENOENT\fP
142 存在しない \fIname\fP のオブジェクトを \fBshm_unlink\fP()  しようとした。
143 .SH バージョン
144 これらの関数は glibc 2.2 以降で提供されている。
145 .SH 準拠
146 POSIX.1\-2001.
147 .LP
148 POSIX.1\-2001 には、新規に作成される共有メモリオブジェクトのグループ所有権は、 呼び出し元プロセスの実効グループ ID か
149 「システムのデフォルトのグループ ID」 のどちらかに設定される、と書かれている。
150 .SH 注意
151 .LP
152 POSIX は \fBO_RDONLY\fP と \fBO_TRUNC\fP が一緒に指定された場合の動作を未定義にしている。Linux では、
153 既存の共有メモリ・オブジェクトに対する切り詰め (truncate) は成功する。 しかし、他の UNIX システムでも同じであるとは限らない。
154 .LP
155 Linux 2.4 における POSIX 共有メモリ・オブジェクトの実装は 専用のファイルシステムを使用する。そのファイルシステムは通常
156 \fI/dev/shm\fP にマウントされる。
157 .SH 関連項目
158 \fBclose\fP(2), \fBfchmod\fP(2), \fBfchown\fP(2), \fBfcntl\fP(2), \fBfstat\fP(2),
159 \fBftruncate\fP(2), \fBmmap\fP(2), \fBopen\fP(2), \fBumask\fP(2), \fBshm_overview\fP(7)