OSDN Git Service

ab8a193f6a9c3680bc7f0ee1493408dd3e6e6ba3
[linuxjm/LDP_man-pages.git] / draft / man7 / sem_overview.7
1 '\" t
2 .\" Hey Emacs! This file is -*- nroff -*- source.
3 .\"
4 .\" Copyright (C) 2006 Michael Kerrisk <mtk.manpages@gmail.com>
5 .\"
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 .\"
26 .\" Japanese Version Copyright (c) 2006 Akihiro MOTOKI all rights reserved.
27 .\" Translated 2006-04-18, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
28 .\" Updated 2008-08-07, Akihiro MOTOKI, LDP v3.05
29 .\" Updated 2009-02-23, Akihiro MOTOKI, LDP v3.19
30 .\"
31 .TH SEM_OVERVIEW 7 2010-05-22 "Linux" "Linux Programmer's Manual"
32 .\"O .SH NAME
33 .SH 名前
34 .\"O sem_overview \- Overview of POSIX semaphores
35 sem_overview \- POSIX セマフォの概要
36 .\"O .SH DESCRIPTION
37 .SH 説明
38 .\"O POSIX semaphores allow processes and threads to synchronize their actions.
39 POSIX セマフォを使用すると、プロセスやスレッド間でその動作を
40 同期させることができる。
41
42 .\"O A semaphore is an integer whose value is never allowed to fall below zero.
43 .\"O Two operations can be performed on semaphores:
44 .\"O increment the semaphore value by one
45 .\"O .RB ( sem_post (3));
46 .\"O and decrement the semaphore value by one
47 .\"O .RB ( sem_wait (3)).
48 .\"O If the value of a semaphore is currently zero, then a
49 .\"O .BR sem_wait (3)
50 .\"O operation will block until the value becomes greater than zero.
51 セマフォは整数であり、その値は決して 0 未満になることは許されない。
52 セマフォに対してできる操作は 2 つである:
53 セマフォ値を 1 増やす
54 .RB ( sem_post (3));
55 セマフォ値を 1 減らす
56 .RB ( sem_wait (3))。
57 セマフォの値がすでに 0 の場合、セマフォ値が 0 より大きくなるまで
58 .BR sem_wait (3)
59 操作は停止 (block) する。
60
61 .\"O POSIX semaphores come in two forms: named semaphores and
62 .\"O unnamed semaphores.
63 POSIX セマフォには、名前付きセマフォ (named semaphore) と
64 名前なしセマフォ (unnamed semaphore) の 2つの形がある。
65 .TP
66 .\"O .B Named semaphores
67 .B 名前付きセマフォ
68 .\"O A named semaphore is identified by a name of the form
69 .\"O .IR /somename ;
70 .\"O that is, a null-terminated string of up to
71 .\"O .BI NAME_MAX \-4
72 .\"O (i.e., 251) characters consisting of an initial slash,
73 名前付きセマフォは
74 .I /somename
75 という形式の名前で識別される。
76 その名前は、最大で
77 .BI NAME_MAX \-4
78 (すなわち 251) 文字の NULL 終端された文字列で、
79 .\" glibc allows the initial slash to be omitted, and makes
80 .\" multiple initial slashes equivalent to a single slash.
81 .\" This differs from the implementation of POSIX message queues.
82 .\"O followed by one or more characters, none of which are slashes.
83 スラッシュで始まり、スラッシュ以外の文字が 1 文字以上続く形式である。
84 .\" glibc allows subdirectory components in the name, in which
85 .\" case the subdirectory tree must exist under /dev/shm, and
86 .\" the fist subdirectory component must exist as the name
87 .\" sem.name, and all of the subdirectory components must allow the
88 .\" required permissions if a user wants to create a semaphore
89 .\" object in a subdirectory.
90 .\"O Two processes can operate on the same named semaphore by passing
91 .\"O the same name to
92 .\"O .BR sem_open (3).
93 .BR sem_open (3)
94 に同じ名前を渡すことにより、2 つのプロセス間で同じ名前のセマフォ
95 に対し操作を行うことができる。
96
97 .\"O The
98 .\"O .BR sem_open (3)
99 .\"O function creates a new named semaphore or opens an existing
100 .\"O named semaphore.
101 .\"O After the semaphore has been opened, it can be operated on using
102 .\"O .BR sem_post (3)
103 .\"O and
104 .\"O .BR sem_wait (3).
105 .\"O When a process has finished using the semaphore, it can use
106 .\"O .BR sem_close (3)
107 .\"O to close the semaphore.
108 .\"O When all processes have finished using the semaphore,
109 .\"O it can be removed from the system using
110 .\"O .BR sem_unlink (3).
111 .BR sem_open (3)
112 関数は、新しい名前付きセマフォを作成するか、既に存在する名前付き
113 セマフォをオープンする。
114 セマフォをオープンした後は、
115 .BR sem_post (3)
116
117 .BR sem_wait (3)
118 を使ってセマフォを操作できる。
119 プロセスがセマフォの使用を終えた際は、
120 .BR sem_close (3)
121 を使ってセマフォをクローズできる。
122 あるセマフォをどのプロセスも使用しなくなると、
123 .BR sem_unlink (3)
124 を使ってそのセマフォをシステムから削除することができる。
125 .TP
126 .\"O .B Unnamed semaphores (memory-based semaphores)
127 .B 名前なしセマフォ (メモリベース・セマフォ)
128 .\"O An unnamed semaphore does not have a name.
129 .\"O Instead the semaphore is placed in a region of memory that
130 .\"O is shared between multiple threads (a
131 .\"O .IR "thread-shared semaphore" )
132 .\"O or processes (a
133 .\"O .IR "process-shared semaphore" ).
134 .\"O A thread-shared semaphore is placed in an area of memory shared
135 .\"O between the threads of a process, for example, a global variable.
136 .\"O A process-shared semaphore must be placed in a shared memory region
137 .\"O (e.g., a System V shared memory segment created using
138 .\"O .BR shmget (2),
139 .\"O or a POSIX shared memory object built created using
140 .\"O .BR shm_open (3)).
141 名前なしセマフォは名前を持たない。その代わり、セマフォは、
142 複数スレッド間で共有されるメモリ領域、もしくは複数プロセス間で
143 共有されたメモリ領域に置かれる (前者を
144 .IR "スレッド共有セマフォ (thread-shared semaphore)" 、
145 後者を
146 .IR "プロセス共有セマフォ (process-shared semaphore)"
147 と呼ぶ)。スレッド共有セマフォは、同じプロセス内のスレッド間で共有される
148 メモリ領域、例えば大域変数 (global variable) に配置される。
149 プロセス共有セマフォは、共有メモリ領域 (例えば、
150 .BR shmget (2)
151 を使って作成できる System V 共有メモリ・セグメントや
152 .BR shm_open (3)
153 を使って作成できる POSIX 共有メモリ・オブジェクト)
154 内に配置しなければならない。
155
156 .\"O Before being used, an unnamed semaphore must be initialized using
157 .\"O .BR sem_init (3).
158 .\"O It can then be operated on using
159 .\"O .BR sem_post (3)
160 .\"O and
161 .\"O .BR sem_wait (3).
162 .\"O When the semaphore is no longer required,
163 .\"O and before the memory in which it is located is deallocated,
164 .\"O the semaphore should be destroyed using
165 .\"O .BR sem_destroy (3).
166 名前なしセマフォは、使用する前に
167 .BR sem_init (3)
168 を使って初期化しなければならない。
169 セマフォは
170 .BR sem_post (3)
171
172 .BR sem_wait (3)
173 を使って操作できる。
174 セマフォがもはや必要なくなったときや、
175 セマフォが置かれているメモリを解放する前には、
176 .BR sem_destroy (3)
177 を使ってセマフォを破棄すべきである。
178 .PP
179 .\"O The remainder of this section describes some specific details
180 .\"O of the Linux implementation of POSIX semaphores.
181 この節の残りでは、POSIX セマフォの Linux の実装の詳細
182 について説明する。
183 .\"O .SS Versions
184 .SS バージョン
185 .\"O Prior to kernel 2.6, Linux only supported unnamed,
186 .\"O thread-shared semaphores.
187 .\"O On a system with Linux 2.6 and a glibc that provides the NPTL
188 .\"O threading implementation,
189 .\"O a complete implementation of POSIX semaphores is provided.
190 バージョン 2.6 より前のカーネルでは、Linux は
191 名前なしのスレッド共有セマフォのみをサポートしていた。
192 Linux 2.6 と NPTL スレッド実装を提供している glibc が入った
193 システムでは、POSIX セマフォの完全な実装が提供される。
194 .\"O .SS Persistence
195 .SS 持続性
196 .\"O POSIX named semaphores have kernel persistence:
197 .\"O if not removed by
198 .\"O .BR sem_unlink (3),
199 .\"O a semaphore will exist until the system is shut down.
200 POSIX 名前付きセマフォはカーネル内で保持される。
201 .BR sem_unlink (3)
202 で削除されなければ、セマフォは
203 システムがシャットダウンされるまで存在し続ける。
204 .\"O .SS Linking
205 .SS リンク
206 .\"O Programs using the POSIX semaphores API must be compiled with
207 .\"O .I cc \-lrt
208 .\"O to link against the real-time library,
209 .\"O .IR librt .
210 POSIX セマフォ API を使用したプログラムは
211 .I cc \-lrt
212 でコンパイルし、リアルタイムライブラリ
213 .I librt
214 とリンクしなければならない。
215 .\"O .SS Accessing named semaphores via the file system
216 .SS ファイルシステム経由での名前付きセマフォへのアクセス
217 .\"O On Linux, named semaphores are created in a virtual file system,
218 .\"O normally mounted under
219 .\"O .IR /dev/shm ,
220 .\"O with names of the form
221 .\"O .IR \fBsem.\fPsomename .
222 Linux では、名前付きセマフォは仮想ファイルシステム
223 (virtual file system) 内に
224 .I \fBsem.\fPsomename
225 という形の名前で作成される。仮想ファイルシステムは通常
226 .I /dev/shm
227 以下にマウントされる。
228 .\"O (This is the reason that semaphore names are limited to
229 .\"O .BI NAME_MAX \-4
230 .\"O rather than
231 .\"O .B NAME_MAX
232 .\"O characters.)
233 (これが、セマフォの名前の文字数の上限が
234 .B NAME_MAX
235 ではなく
236 .BI NAME_MAX \-4
237 となっている理由である。)
238
239 .\"O Since Linux 2.6.19, ACLs can be placed on files under this directory,
240 .\"O to control object permissions on a per-user and per-group basis.
241 Linux 2.6.19 以降では、このディレクトリ配下のファイルに対して ACL を
242 設定でき、オブジェクトへの許可をユーザ単位、グループ単位で制御することが
243 できる。
244 .\"O .SH "CONFORMING TO"
245 .SH 準拠
246 POSIX.1-2001.
247 .\"O .SH NOTES
248 .SH 注意
249 .\"O System V semaphores
250 .\"O .RB ( semget (2),
251 .\"O .BR semop (2),
252 .\"O etc.) are an older semaphore API.
253 .\"O POSIX semaphores provide a simpler, and better designed interface than
254 .\"O System V semaphores;
255 .\"O on the other hand POSIX semaphores are less widely available
256 .\"O (especially on older systems) than System V semaphores.
257 System V セマフォ
258 .RB ( semget (2),
259 .BR semop (2)
260 など) は古いセマフォ API である。 POSIX セマフォは System V よりも
261 簡単で、うまく設計されたインタフェースを提供している。
262 一方で、POSIX セマフォは System V セマフォと比べると
263 利用できるシステムが少ない (特に、古いシステムでは少ない)。
264 .\"O .SH EXAMPLE
265 .SH 例
266 .\"O An example of the use of various POSIX semaphore functions is shown in
267 .\"O .BR sem_wait (3).
268 各種の POSIX セマフォ関数を使用した例が
269 .BR sem_wait (3)
270 に記載されている。
271 .\"O .SH "SEE ALSO"
272 .SH 関連項目
273 .BR sem_close (3),
274 .BR sem_destroy (3),
275 .BR sem_getvalue (3),
276 .BR sem_init (3),
277 .BR sem_open (3),
278 .BR sem_post (3),
279 .BR sem_unlink (3),
280 .BR sem_wait (3),
281 .BR pthreads (7)