1 .\" Hey Emacs! This file is -*- nroff -*- source.
3 .\" Copyright (C) 2002 Michael Kerrisk <mtk.manpages@gmail.com>
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.
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.
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
22 .\" Formatted or processed versions of this manual, if unaccompanied by
23 .\" the source, must acknowledge the copyright and authors of this work.
25 .\" FIXME . Add an example to this page
27 .\" Japanese Version Copyright (c) 2002 Akihiro MOTOKI, all rights reserved.
28 .\" Translated Mon Feb 2 2003 by Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
29 .\" Updated 2009-02-23, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>, LDP v3.19
31 .TH SHM_OPEN 3 2009-02-25 "Linux" "Linux Programmer's Manual"
33 shm_open, shm_unlink \- POSIX 共有メモリ・オブジェクトの作成/オープン、
36 .B #include <sys/mman.h>
38 .BR "#include <sys/stat.h>" " /* mode 定数用 */"
40 .BR "#include <fcntl.h>" " /* O_* 定数の定義用 */"
42 .BI "void * shm_open(const char *" name ", int " oflag ", mode_t " mode );
44 .BI "int shm_unlink(const char *" name );
49 は、POSIX 共有メモリ・オブジェクトを新規に作成/オープンしたり、
50 すでに存在するオブジェクトをオープンしたりする。
51 POSIX 共有メモリ・オブジェクトは、実際には、関係のないプロセスが
65 で作成したりオープンしたりする共有メモリ・オブジェクトを指定する。
66 移植性を持たせるためには、共有メモリ・オブジェクトは
71 (すなわち 255) 文字の NULL 終端された文字列で、
72 .\" glibc allows the initial slash to be omitted, and makes
73 .\" multiple initial slashes equivalent to a single slash.
74 .\" This differs from the implementation of POSIX message queues.
75 スラッシュで始まり、スラッシュ以外の文字が 1 文字以上続く形式
77 .\" glibc allows subdirectory components in the name, in which
78 .\" case the subdirectory must exist under /dev/shm, and allow the
79 .\" required permissions if a user wants to create a shared memory
80 .\" object in that subdirectory.
87 のいずれか一方と、以下に述べる他のフラグの論理和をとったもの
91 読み出しアクセス用にオブジェクトをオープンする。
92 このフラグを指定してオープンされた共有メモリ・オブジェクトは、
93 読み出し (\fBPROT_READ\fP) アクセスでのみ
98 読み書きアクセス用にオブジェクトをオープンする。
101 存在しない場合、共有メモリ・オブジェクトを作成する。
102 オブジェクトのユーザとグループの所有権は、
103 呼び出し元プロセスの対応する実効 ID が使われ、
104 .\" 本当は、Linux ではファイルシステム ID が使われるのだが、
105 .\" その値はほとんどいつも実効 ID と同じである。 (MTK, Jul 05)
108 の下位 9 ビットに基づいて設定される。ただし、
111 参照) に設定されている値は、新規オブジェクトに関してはクリアされる。
113 を定義するために使用できるマクロ定数(群)は
120 新規に作成された共有メモリ・オブジェクトは長さ 0 で初期化される。
124 共有メモリ・オブジェクトとして新規に確保されたバイトは自動的に
131 で指定された共有メモリ・オブジェクトが既に存在した場合、
133 オブジェクトの存在確認と、存在しなかった場合のオブジェクト作成は、
134 必ず一連の操作として実行される (performed atomically)。
137 共有メモリ・オブジェクトがすでに存在した場合、
138 そのオブジェクトを 0 バイトに切り詰める。
146 は共有メモリ・オブジェクトを参照する新しいファイル・ディスクリプタを返す。
147 このファイル・ディスクリプタは、そのプロセス内で過去にオープンされていない
148 ファイル・ディスクリプタの中で最も小さな数になることが保証される。
152 を参照) が、このファイル・ディスクリプタに設定される。
154 通常、これらのファイル・ディスクリプタは、この後続けて実行される
156 (新規に作成されたオブジェクトの場合のみ) と
160 を呼び出した後は、ファイル・ディスクリプタをクローズしてもよく、
161 クローズしてもメモリ・マッピングに影響を与えることはない。
167 共有メモリ・オブジェクト名を削除し、すべてのプロセスが処理対象の
168 オブジェクトをアンマップした時点でオブジェクトの割り当てを解除し、
179 が指定されている場合、新しく別のオブジェクトが作成される)。
188 は、成功した場合 0 を、エラーが起こった場合 \-1 を返す。
210 が指定されたが、呼び出し元にはそのオブジェクトに対する書き込み権限が
221 で指定された共有メモリ・オブジェクトが既に存在した。
230 プロセスがオープン可能なファイル数の上限にすでに達していた。
239 ファイルシステムでオープンできるファイル数の上限に達した。
257 これらの関数は glibc 2.2 以降で提供されている。
261 POSIX.1-2001 には、新規に作成される共有メモリオブジェクトのグループ所有権は、
262 呼び出し元プロセスの実効グループ ID か 「システムのデフォルトのグループ ID」
270 が一緒に指定された場合の動作を未定義にしている。Linux では、
271 既存の共有メモリ・オブジェクトに対する切り詰め (truncate) は成功する。
272 しかし、他の UNIX システムでも同じであるとは限らない。
274 Linux 2.4 における POSIX 共有メモリ・オブジェクトの実装は
275 専用のファイルシステムを使用する。そのファイルシステムは通常