• R/O
  • HTTP
  • SSH
  • HTTPS

jm: Commit

翻訳ドキュメント管理用


Commit MetaInfo

Revisióncc04853ad4971cf31b117db6f5b4198c61ea5f57 (tree)
Tiempo2021-04-01 15:44:24
AutorAkihiro Motoki <amotoki@gmai...>
CommiterAkihiro Motoki

Log Message

LDP: Update draft based on the previous commit (semaphore)

Cambiar Resumen

Diferencia incremental

--- /dev/null
+++ b/manual/LDP_man-pages/draft/man2/semctl.2
@@ -0,0 +1,377 @@
1+.\" Copyright 1993 Giorgio Ciucci (giorgio@crcc.it)
2+.\" and Copyright 2004, 2005 Michael Kerrisk <mtk.manpages@gmail.com>
3+.\"
4+.\" %%%LICENSE_START(VERBATIM)
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+.\" %%%LICENSE_END
25+.\"
26+.\" Modified Tue Oct 22 17:53:56 1996 by Eric S. Raymond <esr@thyrsus.com>
27+.\" Modified Fri Jun 19 10:59:15 1998 by Andries Brouwer <aeb@cwi.nl>
28+.\" Modified Sun Feb 18 01:59:29 2001 by Andries Brouwer <aeb@cwi.nl>
29+.\" Modified 20 Dec 2001, Michael Kerrisk <mtk.manpages@gmail.com>
30+.\" Modified 21 Dec 2001, aeb
31+.\" Modified 27 May 2004, Michael Kerrisk <mtk.manpages@gmail.com>
32+.\" Added notes on CAP_IPC_OWNER requirement
33+.\" Modified 17 Jun 2004, Michael Kerrisk <mtk.manpages@gmail.com>
34+.\" Added notes on CAP_SYS_ADMIN requirement for IPC_SET and IPC_RMID
35+.\" Modified, 11 Nov 2004, Michael Kerrisk <mtk.manpages@gmail.com>
36+.\" Language and formatting clean-ups
37+.\" Rewrote semun text
38+.\" Added semid_ds and ipc_perm structure definitions
39+.\" 2005-08-02, mtk: Added IPC_INFO, SEM_INFO, SEM_STAT descriptions.
40+.\" 2018-03-20, dbueso: Added SEM_STAT_ANY description.
41+.\"
42+.\"*******************************************************************
43+.\"
44+.\" This file was generated with po4a. Translate the source file.
45+.\"
46+.\"*******************************************************************
47+.\"
48+.\" Japanese Version Copyright (c) 1997,1998 HANATAKA Shinya
49+.\" all rights reserved.
50+.\" Translated 1997-02-23, HANATAKA Shinya <hanataka@abyss.rim.or.jp>
51+.\" Modified 1998-09-10, HANATAKA Shinya <hanataka@abyss.rim.or.jp>
52+.\" Updated & Modified 2001-06-03, Yuichi SATO <ysato@h4.dion.ne.jp>
53+.\" Updated & Modified 2002-01-02, Yuichi SATO
54+.\" Updated & Modified 2005-01-03, Yuichi SATO <ysato444@yahoo.co.jp>
55+.\" Updated & Modified 2005-10-10, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
56+.\" Updated 2013-05-06, Akihiro MOTOKI <amotoki@gmail.com>
57+.\" Updated 2013-07-24, Akihiro MOTOKI <amotoki@gmail.com>
58+.\"
59+.TH SEMCTL 2 2020\-12\-21 Linux "Linux Programmer's Manual"
60+.SH 名前
61+semctl \- System V セマフォの制御操作を行なう
62+.SH 書式
63+.nf
64+\fB#include <sys/types.h>\fP
65+\fB#include <sys/ipc.h>\fP
66+\fB#include <sys/sem.h>\fP
67+.PP
68+\fBint semctl(int \fP\fIsemid\fP\fB, int \fP\fIsemnum\fP\fB, int \fP\fIcmd\fP\fB, ...);\fP
69+.fi
70+.SH 説明
71+\fBsemctl\fP() は、 \fIsemid\fP で指定された System\ V セマフォ集合 (semaphore set) またはセマフォ集合の
72+\fIsemnun\fP 番目のセマフォに対して、 \fIcmd\fP で指定された制御操作を行なう (集合内のセマフォの番号は 0 から始まる)。
73+.PP
74+この関数は、 \fIcmd\fP の値に依存して、3 個または 4 個の引き数を持つ。 引き数が 4 個の場合、第 4 引き数の型は \fIunion
75+semun\fP である。 \fI呼び出し元プログラム\fPは、 この共用体 (union) を以下のように定義しなければならない。
76+.PP
77+.in +4n
78+.EX
79+union semun {
80+ int val; /* SETVAL の値 */
81+ struct semid_ds *buf; /* IPC_STAT, IPC_SET 用のバッファー */
82+ unsigned short *array; /* GETALL, SETALL 用の配列 */
83+ struct seminfo *__buf; /* IPC_INFO 用のバッファー
84+ (Linux 固有) */
85+};
86+.EE
87+.in
88+.PP
89+\fIsemid_ds\fP データ構造体は \fI<sys/sem.h>\fP で以下のように定義されている:
90+.PP
91+.in +4n
92+.EX
93+struct semid_ds {
94+ struct ipc_perm sem_perm; /* 所有権と許可 */
95+ time_t sem_otime; /* 最後の semop の時刻 */
96+ time_t sem_ctime; /* 作成時刻/semctl() により
97+ 最後に変更が行われた時刻 */
98+ unsigned long sem_nsems; /* 集合内のセマフォの数 */
99+};
100+.EE
101+.in
102+.PP
103+The fields of the \fIsemid_ds\fP structure are as follows:
104+.TP 11
105+\fIsem_perm\fP
106+This is an \fIipc_perm\fP structure (see below) that specifies the access
107+permissions on the semaphore set.
108+.TP
109+\fIsem_otime\fP
110+Time of last \fBsemop\fP(2) system call.
111+.TP
112+\fIsem_ctime\fP
113+Time of creation of semaphore set or time of last \fBsemctl\fP() \fBIPCSET\fP,
114+\fBSETVAL\fP, or \fBSETALL\fP operation.
115+.TP
116+\fIsem_nsems\fP
117+Number of semaphores in the set. Each semaphore of the set is referenced by
118+a nonnegative integer ranging from \fB0\fP to \fIsem_nsems\-1\fP.
119+.PP
120+\fIipc_perm\fP 構造体は以下のように定義されている (強調されたフィールドは \fBIPC_SET\fP を使って設定可能である):
121+.PP
122+.in +4n
123+.EX
124+struct ipc_perm {
125+ key_t __key; /* semget(2) に与えられるキー */
126+ uid_t \fBuid\fP; /* 所有者 (owner) の実効 UID */
127+ gid_t \fBgid\fP; /* 所有者の実効 GID */
128+ uid_t cuid; /* 作成者 (creator) の実効 UID */
129+ gid_t cgid; /* 作成者の実効 GID */
130+ unsigned short \fBmode\fP; /* 許可 */
131+ unsigned short __seq; /* シーケンス番号 */
132+};
133+.EE
134+.in
135+.PP
136+The least significant 9 bits of the \fImode\fP field of the \fIipc_perm\fP
137+structure define the access permissions for the shared memory segment. The
138+permission bits are as follows:
139+.TS
140+l l.
141+0400 Read by user
142+0200 Write by user
143+0040 Read by group
144+0020 Write by group
145+0004 Read by others
146+0002 Write by others
147+.TE
148+.PP
149+In effect, "write" means "alter" for a semaphore set. Bits 0100, 0010, and
150+0001 (the execute bits) are unused by the system.
151+.PP
152+\fIcmd\fP として有効な値は次の通りである。
153+.TP
154+\fBIPC_STAT\fP
155+\fIsemid\fP に関連づけられたカーネルデータ構造体の情報を \fIarg.buf\fP で指された \fIsemid_ds\fP 構造体へコピーする。
156+\fIsemnum\fP 引き数は無視される。 呼び出したプロセスはそのセマフォ集合に対する 読み込み許可を持たなければならない。
157+.TP
158+\fBIPC_SET\fP
159+Write the values of some members of the \fIsemid_ds\fP structure pointed to by
160+\fIarg.buf\fP to the kernel data structure associated with this semaphore set,
161+updating also its \fIsem_ctime\fP member.
162+.IP
163+The following members of the structure are updated: \fIsem_perm.uid\fP,
164+\fIsem_perm.gid\fP, and (the least significant 9 bits of) \fIsem_perm.mode\fP.
165+.IP
166+The effective UID of the calling process must match the owner
167+(\fIsem_perm.uid\fP) or creator (\fIsem_perm.cuid\fP) of the semaphore set, or
168+the caller must be privileged. The argument \fIsemnum\fP is ignored.
169+.TP
170+\fBIPC_RMID\fP
171+セマフォ集合をただちに削除し、その集合上の \fBsemop\fP(2) コールでブロックされている全てのプロセスを目覚めさせる (エラー値が返されて、
172+\fIerrno\fP に \fBEIDRM\fP が設定される)。 呼び出したプロセスの実効ユーザー ID が そのセマフォ集合の作成者または所有者と一致するか、
173+呼び出した人が特権を持たなければならない。 \fIsemnum\fP 引き数は無視される。
174+.TP
175+\fBIPC_INFO\fP (Linux 固有)
176+システム全体でのセマフォの制限とパラメーターに関する情報を、 \fIarg.__buf\fP が指す構造体に入れて返す。 この構造体は \fIseminfo\fP
177+型である。 \fIseminfo\fP は \fB_GNU_SOURCE\fP 機能検査マクロが定義された場合に \fI<sys/sem.h>\fP
178+で以下のように定義される:
179+.IP
180+.in +4n
181+.EX
182+struct seminfo {
183+ int semmap; /* セマフォマップの最大エントリー数;
184+ カーネル内では未使用 */
185+ int semmni; /* セマフォ集合の最大数 */
186+ int semmns; /* 全セマフォ集合中のセマフォの
187+ 最大数 */
188+ int semmnu; /* アンドゥ構造体のシステム全体での
189+ 最大数; カーネル内では未使用 */
190+ int semmsl; /* 一つのセマフォ集合の最大セマフォ数 */
191+ int semopm; /* semop(2) に渡す操作の最大数 */
192+ int semume; /* プロセスあたりのアンドゥエントリー
193+ の最大数; カーネル内では未使用 */
194+ int semusz; /* 構造体 sem_undo のサイズ */
195+ int semvmx; /* セマフォの最大値 */
196+ int semaem; /* セマフォの調整 (semaphore adjustment;
197+ SEM_UNDO) のために記録される最大値 */
198+};
199+.EE
200+.in
201+.IP
202+設定 \fIsemmsl\fP, \fIsemmns\fP, \fIsemopm\fP, \fIsemmni\fP は \fI/proc/sys/kernel/sem\fP
203+経由で変更可能である。 詳しくは \fBproc\fP(5) を参照。
204+.TP
205+\fBSEM_INFO\fP (Linux 固有)
206+\fBIPC_INFO\fP のときと同じ情報を格納した \fIseminfo\fP 構造体を返す。 但し、以下のフィールドにはセマフォが消費しているシステム資源に
207+関する情報が格納される点が異なる。 \fIsemusz\fP フィールドは現在システム上に存在するセマフォ集合の数を返す。 \fIsemaem\fP
208+フィールドはシステム上の全てのセマフォ集合に含まれる セマフォの総数を返す。
209+.TP
210+\fBSEM_STAT\fP (Linux 固有)
211+\fBIPC_STAT\fP と同じく \fIsemid_ds\fP 構造体を返す。 但し、 \fIsemid\fP
212+引き数は、セマフォ識別子ではなく、システム上の全てのセマフォ集合 に関する情報を管理するカーネルの内部配列へのインデックスである。
213+.TP
214+\fBSEM_STAT_ANY\fP (Linux 固有, Linux 4.17 以降)
215+Return a \fIseminfo\fP structure containing the same information as for
216+\fBSEM_STAT\fP. However, \fIsem_perm.mode\fP is not checked for read access for
217+\fIsemid\fP meaning that any user can employ this operation (just as any user
218+may read \fI/proc/sysvipc/sem\fP to obtain the same information).
219+.TP
220+\fBGETALL\fP
221+集合の全てのセマフォの \fBsemval\fP の値 (現在の値) を \fIarg.array\fP に返す。 \fIsemnum\fP 引き数は無視される。
222+呼び出したプロセスはそのセマフォ集合に読み込み許可を持たなければならない。
223+.TP
224+\fBGETNCNT\fP
225+Return the \fBsemncnt\fP value for the \fIsemnum\fP\-th semaphore of the set (i.e.,
226+the number of processes waiting for the semaphore's value to increase). The
227+calling process must have read permission on the semaphore set.
228+.TP
229+\fBGETPID\fP
230+集合の \fIsemnum\fP 番目のセマフォの \fBsempid\fP の値を返す。この値は、そのセマフォに対して最後に操作を行ったプロセスの PID である
231+(ただし「バグ」を参照)。呼び出したプロセスはそのセマフォ集合に読み込み許可を持たなければならない。
232+.TP
233+\fBGETVAL\fP
234+集合の \fIsemnum\fP 番目のセマフォの \fBsemval\fP (セマフォの値) を返す。
235+呼び出したプロセスはそのセマフォ集合に読み込み許可を持たなければならない。
236+.TP
237+\fBGETZCNT\fP
238+集合の \fIsemnum\fP 番目のセマフォの \fBsemzcnt\fP の値 (つまり、そのセマフォの値が 0 になるのを待っているプロセスの数)
239+を返す。呼び出したプロセスはそのセマフォ集合に読み込み許可を持たなければならない。
240+.TP
241+\fBSETALL\fP
242+集合の全てのセマフォの \fBsemval\fP 値に \fIarg.array\fP で指定された値を設定する。 その集合に関連する \fIsemid_ds\fP
243+構造体の \fIsem_ctime\fP メンバーの値も更新する。 全てのプロセスのセマフォの変更についてのアンドゥエントリー (\fBsemop\fP(2)
244+を参照) は消去 (clear) される。 セマフォの値の変更により、他のプロセス内でブロックされている \fBsemop\fP(2)
245+コールの続行が許可されると、それらのプロセスは起こされる (wake up)。 \fIsemnum\fP 引き数は無視される。
246+呼び出したプロセスはそのセマフォ集合に 変更 (書き込み) 許可を持たなければならない。
247+.TP
248+\fBSETVAL\fP
249+集合の \fIsemnum\fP 番目のセマフォのセマフォ地 (\fBsemval\fP) に \fIarg.val\fP の値を設定する。その集合に関連する
250+\fIsemid_ds\fP 構造体の \fIsem_ctime\fP メンバーの値も更新する。
251+全てのプロセスのセマフォの変更についてのアンドゥエントリーは消去される。 セマフォの値の変更により、他のプロセス内でブロックされている
252+\fBsemop\fP(2) コールの続行が許可されると、それらのプロセスは起こされる (wake up)。 呼び出したプロセスはそのセマフォ集合に 変更
253+(書き込み) 許可を持たなければならない。
254+.SH 返り値
255+失敗した場合、 \fBsemctl\fP() は \-1 を返し、 \fIerrno\fP にそのエラーを示す。
256+.PP
257+そうでなければシステムコールは \fIcmd\fP によって以下の負でない値を返す:
258+.TP
259+\fBGETNCNT\fP
260+\fBsemncnt\fP の値
261+.TP
262+\fBGETPID\fP
263+\fBsempid\fP の値
264+.TP
265+\fBGETVAL\fP
266+\fBsemval\fP の値
267+.TP
268+\fBGETZCNT\fP
269+\fBsemzcnt\fP の値
270+.TP
271+\fBIPC_INFO\fP
272+全てのセマフォ集合に関する情報を管理しているカーネルの内部配列の使用中 エントリーのインデックスの最大値
273+(この情報は、システムの全てのセマフォ集合に関する情報を取得するために操作 \fBSEM_STAT\fP や \fBSEM_STAT_ANY\fP
274+を繰り返し実行する際に使用できる)
275+.TP
276+\fBSEM_INFO\fP
277+\fBIPC_INFO\fP と同じ
278+.TP
279+\fBSEM_STAT\fP
280+\fIsemid\fP で指定されたインデックスを持つセマフォ集合の識別子
281+.TP
282+\fBSEM_STAT_ANY\fP
283+\fBSEM_STAT\fP と同じ。
284+.PP
285+\fIcmd\fP の値がそれ以外の場合、成功すると 0 が返される。
286+.SH エラー
287+失敗した場合は \fIerrno\fP には以下の値のどれかが設定される:
288+.TP
289+\fBEACCES\fP
290+The argument \fIcmd\fP has one of the values \fBGETALL\fP, \fBGETPID\fP, \fBGETVAL\fP,
291+\fBGETNCNT\fP, \fBGETZCNT\fP, \fBIPC_STAT\fP, \fBSEM_STAT\fP, \fBSEM_STAT_ANY\fP,
292+\fBSETALL\fP, or \fBSETVAL\fP and the calling process does not have the required
293+permissions on the semaphore set and does not have the \fBCAP_IPC_OWNER\fP
294+capability in the user namespace that governs its IPC namespace.
295+.TP
296+\fBEFAULT\fP
297+\fIarg.buf\fP または \fIarg.array\fP で指されているアドレスにアクセスすることができない。
298+.TP
299+\fBEIDRM\fP
300+セマフォ集合が削除された。
301+.TP
302+\fBEINVAL\fP
303+\fIcmd\fP または \fIsemid\fP に無効な値が指定された。 もしくは、 \fBSEM_STAT\fP 操作の場合に、 \fIsemid\fP
304+で指定されたインデックス値が現在未使用の配列のスロットを参照いていた。
305+.TP
306+\fBEPERM\fP
307+\fIcmd\fP 引き数に \fBIPC_SET\fP または \fBIPC_RMID\fP が指定され、呼び出したプロセスの実効ユーザー ID がセマフォの
308+(\fIsem_perm.cuid\fP で見つかる) 作成者または (\fIsem_perm.uid\fP で見つかる) 所有者でもなく、 プロセスが
309+\fBCAP_SYS_ADMIN\fP ケーパビリティを持たない。
310+.TP
311+\fBERANGE\fP
312+\fIcmd\fP 引き数に \fBSETALL\fP または \fBSETVAL\fP が指定され、(集合のセマフォのどれかの) \fBsemval\fP に設定される値が
313+0 より小さいか、実装の制限 \fBSEMVMX\fP よりも大きい。
314+.SH 準拠
315+.\" SVr4 documents more error conditions EINVAL and EOVERFLOW.
316+POSIX.1\-2001, POSIX.1\-2008, SVr4.
317+.PP
318+.\" POSIX.1-2001, POSIX.1-2008
319+POSIX.1 では \fIsemid_ds\fP 構造体の \fIsem_nsems\fP フィールドは \fIunsigned\ short\fP
320+型を持つと規定されており、 他のほとんどのシステムでこのフィールドは \fIunsigned\ short\fP 型になっている。 Linux 2.4
321+以前ではそうなっていたが、 Linux 2.4 以降ではこのフィールドは \fIunsigned\ long\fP 型である。
322+.SH 注意
323+.\" Like Linux, the FreeBSD man pages still document
324+.\" the inclusion of these header files.
325+Linux や POSIX の全てのバージョンでは、 \fI<sys/types.h>\fP と \fI<sys/ipc.h>\fP
326+のインクルードは必要ない。しかしながら、いくつかの古い実装ではこれらのヘッダーファイルのインクルードが必要であり、 SVID
327+でもこれらのインクルードをするように記載されている。このような古いシステムへの移植性を意図したアプリケーションではこれらのファイルをインクルードする必要があるかもしれない。
328+.PP
329+\fBIPC_INFO\fP, \fBSEM_STAT\fP, \fBSEM_INFO\fP 操作は \fBipcs\fP(1)
330+プログラムによって割当られた資源について情報を提供するために使用される。 将来的にはこれらは変更されるか、 \fI/proc\fP
331+ファイルシステムインターフェースに移動されるかもしれない。
332+.PP
333+\fI構造体 semid_ds\fP 内の多くのフィールドは、 Linux 2.2 では \fIshort\fP 型だったが、Linux 2.4 では
334+\fIlong\fP 型になった。 この利点を生かすには、glibc\-2.1.91 以降の環境下で 再コンパイルすれば十分である。
335+カーネルは新しい形式の呼び出しと古い形式の呼び出しを \fIcmd\fP 内の \fBIPC_64\fP フラグで区別する。
336+.PP
337+.\" POSIX.1-2001, POSIX.1-2008
338+初期のバージョンの glibc では、 \fIsemun\fP 共用体は \fI<sys/sem.h>\fP で定義されていたが、 POSIX.1
339+では呼び出し側がこの共用体を定義する必要がある。 この共用体が定義されて\fIいない\fP glibc のバージョンでは、 マクロ
340+\fB_SEM_SEMUN_UNDEFINED\fP が \fI<sys/sem.h>\fP で定義されている。
341+.PP
342+以下は \fBsemctl\fP() コールに影響するセマフォ集合のシステム制限:
343+.TP
344+\fBSEMVMX\fP
345+\fBsemval\fP の最大値 : 実装依存 (32767)。
346+.PP
347+.\"
348+移植性を高めるための一番良い方法は、常に 4 個の引き数で \fBsemctl\fP() を呼び出すことである。
349+.SS "The sempid value"
350+POSIX.1 defines \fIsempid\fP as the "process ID of [the] last operation" on a
351+semaphore, and explicitly notes that this value is set by a successful
352+\fBsemop\fP(2) call, with the implication that no other interface affects the
353+\fIsempid\fP value.
354+.PP
355+.\" At least OpenSolaris (and, one supposes, older Solaris) and Darwin
356+While some implementations conform to the behavior specified in POSIX.1,
357+others do not. (The fault here probably lies with POSIX.1 inasmuch as it
358+likely failed to capture the full range of existing implementation
359+behaviors.) Various other implementations also update \fIsempid\fP for the
360+other operations that update the value of a semaphore: the \fBSETVAL\fP and
361+\fBSETALL\fP operations, as well as the semaphore adjustments performed on
362+process termination as a consequence of the use of the \fBSEM_UNDO\fP flag (see
363+\fBsemop\fP(2)).
364+.PP
365+.\" commit a5f4db877177d2a3d7ae62a7bac3a5a27e083d7f
366+Linux also updates \fIsempid\fP for \fBSETVAL\fP operations and semaphore
367+adjustments. However, somewhat inconsistently, up to and including Linux
368+4.5, the kernel did not update \fIsempid\fP for \fBSETALL\fP operations. This was
369+rectified in Linux 4.6.
370+.SH 例
371+\fBshmop\fP(2) 参照。
372+.SH 関連項目
373+\fBipc\fP(2), \fBsemget\fP(2), \fBsemop\fP(2), \fBcapabilities\fP(7),
374+\fBsem_overview\fP(7), \fBsysvipc\fP(7)
375+.SH この文書について
376+この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 5.10 の一部である。プロジェクトの説明とバグ報告に関する情報は
377+\%https://www.kernel.org/doc/man\-pages/ に書かれている。
--- /dev/null
+++ b/manual/LDP_man-pages/draft/man2/semget.2
@@ -0,0 +1,304 @@
1+.\" Copyright 1993 Giorgio Ciucci (giorgio@crcc.it)
2+.\" and Copyright (C) 2020 Michael Kerrisk <mtk.manpages@gmail.com>
3+.\"
4+.\" %%%LICENSE_START(VERBATIM)
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+.\" %%%LICENSE_END
25+.\"
26+.\" Modified Tue Oct 22 17:54:56 1996 by Eric S. Raymond <esr@thyrsus.com>
27+.\" Modified 1 Jan 2002, Martin Schulze <joey@infodrom.org>
28+.\" Modified 4 Jan 2002, Michael Kerrisk <mtk.manpages@gmail.com>
29+.\" Modified, 27 May 2004, Michael Kerrisk <mtk.manpages@gmail.com>
30+.\" Added notes on capability requirements
31+.\" Modified, 11 Nov 2004, Michael Kerrisk <mtk.manpages@gmail.com>
32+.\" Language and formatting clean-ups
33+.\" Added notes on /proc files
34+.\" Rewrote BUGS note about semget()'s failure to initialize
35+.\" semaphore values
36+.\"
37+.\"*******************************************************************
38+.\"
39+.\" This file was generated with po4a. Translate the source file.
40+.\"
41+.\"*******************************************************************
42+.\"
43+.\" Japanese Version Copyright (c) 1997 HANATAKA Shinya
44+.\" all rights reserved.
45+.\" Translated 1997-02-23, HANATAKA Shinya <hanataka@abyss.rim.or.jp>
46+.\" Updated 2003-04-08, Kentaro Shirakata <argrath@ub32.org>
47+.\" Updated 2005-03-01, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
48+.\" Updated 2006-07-20, Akihiro MOTOKI, LDP v2.36
49+.\" Updated 2013-05-01, Akihiro MOTOKI <amotoki@gmail.com>
50+.\"
51+.TH SEMGET 2 2020\-04\-11 Linux "Linux Programmer's Manual"
52+.SH 名前
53+semget \- System V セマフォ集合の識別子を取得する
54+.SH 書式
55+.nf
56+\fB#include <sys/types.h>\fP
57+\fB#include <sys/ipc.h>\fP
58+\fB#include <sys/sem.h>\fP
59+.fi
60+.PP
61+\fBint semget(key_t \fP\fIkey\fP\fB,\fP \fBint \fP\fInsems\fP\fB,\fP \fBint \fP\fIsemflg\fP\fB);\fP
62+.SH 説明
63+The \fBsemget\fP() system call returns the System\ V semaphore set identifier
64+associated with the argument \fIkey\fP. It may be used either to obtain the
65+identifier of a previously created semaphore set (when \fIsemflg\fP is zero and
66+\fIkey\fP does not have the value \fBIPC_PRIVATE\fP), or to create a new set.
67+.PP
68+\fIkey\fP の値が \fBIPC_PRIVATE\fP の場合、もしくは \fIsemflg\fP に \fBIPC_CREAT\fP が指定されていて、 \fIkey\fP
69+に対応するセマフォ集合が存在しない場合、 \fInsems\fP 個のセマフォからなる新しい集合が作成される。
70+.PP
71+\fIsemflg\fP に \fBIPC_CREAT\fP と \fBIPC_EXCL\fP の両方が指定された場合、 \fIkey\fP
72+に対応するセマフォ集合が既に存在すると、 \fBsemget\fP() は失敗し、 \fIerrno\fP に \fBEEXIST\fP が設定される (これは
73+\fBopen\fP(2) に \fBO_CREAT | O_EXCL\fP が指定された場合の動作と同じである)。
74+.PP
75+セマフォ集合作成時に、引き数 \fIsemflg\fP の下位 9 ビットは、そのセマフォ集合の (所有者 (owner)、グループ (group)、 他人
76+(others) に対する) アクセス許可の定義として使用される。 これらのビットは \fBopen\fP(2) の引き数 \fImode\fP
77+と同じ形式で同じ意味である (但し、実行 (execute) 許可はセマフォでは意味を持たず、 書き込み (write) 許可はセマフォ値の変更
78+(alter) 許可として機能する)。
79+.PP
80+新規のセマフォ集合を作成する際、 \fBsemget\fP() はセマフォ集合の情報を保持するデータ構造体 \fIsemid_ds\fP を次のように初期化する
81+(\fIsemid_ds\fP については \fBsemctl\fP(2) を参照):
82+.IP \(bu 2
83+\fIsem_perm.cuid\fP と \fIsem_perm.uid\fP に、呼び出し元のプロセスの実効 (effective) ユーザー ID
84+を設定する。
85+.IP \(bu
86+\fIsem_perm.cgid\fP と \fIsem_perm.gid\fP に、呼び出し元のプロセスの実効 (effective) グループ ID
87+を設定する。
88+.IP \(bu
89+\fIsem_perm.mode\fP の下位 9 ビットに \fIsemflg\fP の下位 9 ビットを設定する。
90+.IP \(bu
91+\fIsem_nsems\fP に \fInsems\fP の値を設定する。
92+.IP \(bu
93+\fIsem_otime\fP に 0 を設定する。
94+.IP \(bu
95+\fIsem_ctime\fP に現在の時刻を設定する。
96+.PP
97+セマフォ集合の作成を行わない場合は、引き数 \fInsems\fP に (don't care を意味する) 0 を指定してもよい。 そうでない場合は、
98+\fInsems\fP は 0 より大きい値でなければならず、セマフォ集合あたりのセマフォの最大数 (\fBSEMMSL\fP) 以下でなければならない。
99+.PP
100+.\" and a check is made to see if it is marked for destruction.
101+セマフォ集合が既に存在した場合は、アクセス許可の検査が行われる。
102+.SH 返り値
103+成功した場合、セマフォ集合の識別子 (非負の整数) が返り値となる。 失敗した場合は \-1 が返され、 \fIerrno\fP にエラーを示す値が設定される。
104+.SH エラー
105+失敗した場合は \fIerrno\fP には以下の値のどれかが設定される:
106+.TP
107+\fBEACCES\fP
108+A semaphore set exists for \fIkey\fP, but the calling process does not have
109+permission to access the set, and does not have the \fBCAP_IPC_OWNER\fP
110+capability in the user namespace that governs its IPC namespace.
111+.TP
112+\fBEEXIST\fP
113+.\" .TP
114+.\" .B EIDRM
115+.\" The semaphore set is marked to be deleted.
116+\fIsemflg\fP に \fBIPC_CREAT\fP と \fBIPC_EXCL\fP が指定されたが、 \fIkey\fP に対応するセマフォ集合はすでに存在する。
117+.TP
118+\fBEINVAL\fP
119+\fInsems\fP が 0 より小さいか、 セマフォ集合あたりのセマフォの最大数 (\fBSEMMSL\fP) より大きい。
120+.TP
121+\fBEINVAL\fP
122+\fIkey\fP に対応するセマフォ集合が既に存在するが、 \fInsems\fP がその集合のセマフォ数よりも大きい。
123+.TP
124+\fBENOENT\fP
125+\fIkey\fP に対応するセマフォ集合が存在せず、 \fIsemflg\fP に \fBIPC_CREAT\fP が指定されてもいない。
126+.TP
127+\fBENOMEM\fP
128+セマフォ集合を作成しようとしたが、新しいデータ構造体を 作成するのに十分なメモリーがシステムに存在しない。
129+.TP
130+\fBENOSPC\fP
131+セマフォ集合を作成しようとすると、システムのセマフォ集合の 最大数 (\fBSEMMNI\fP) か、システム全体のセマフォの最大数 (\fBSEMMNS\fP)
132+のいずれかを超えてしまう。
133+.SH 準拠
134+.\" SVr4 documents additional error conditions EFBIG, E2BIG, EAGAIN,
135+.\" ERANGE, EFAULT.
136+SVr4, POSIX.1\-2001.
137+.SH 注意
138+.\" Like Linux, the FreeBSD man pages still document
139+.\" the inclusion of these header files.
140+Linux や POSIX の全てのバージョンでは、 \fI<sys/types.h>\fP と \fI<sys/ipc.h>\fP
141+のインクルードは必要ない。しかしながら、いくつかの古い実装ではこれらのヘッダーファイルのインクルードが必要であり、 SVID
142+でもこれらのインクルードをするように記載されている。このような古いシステムへの移植性を意図したアプリケーションではこれらのファイルをインクルードする必要があるかもしれない。
143+.PP
144+.\"
145+\fBIPC_PRIVATE\fP はフラグフィールドに指定するものではなく、 \fIkey_t\fP 型である。 この特別な値が \fIkey\fP に指定されると、
146+\fBsemget\fP() \fIsemflg\fP の下位 9 ビット以外は全て無視し、 (成功した場合は) 新しいセマフォ集合を作成する。
147+.SS セマフォの初期化
148+.\" In truth, every one of the many implementations that I've tested sets
149+.\" the values to zero, but I suppose there is/was some obscure
150+.\" implementation out there that does not.
151+新しく作成されたセマフォ集合の各セマフォの値は不定である。 (この点は POSIX.1\-2001 と POSIX.1\-2008
152+に明記されている。ただし、POSIX.1\-2008 では POSIX の将来のバージョンではセマフォを 0
153+に初期化するように実装に要求する可能性が注記されている。) Linux は他の多くの実装と同様にセマフォ値を 0 に初期化するが、
154+移植性を考慮したアプリケーションではこの動作を前提にすべきではない。 アプリケーションは明示的にセマフォを希望の値で初期化すべきである。
155+.PP
156+.\"
157+\fBsemctl\fP(2) の \fBSETVAL\fP か \fBSETALL\fP 操作を使って初期化することができる。
158+複数箇所からセマフォ集合の操作が行われる場面では、 誰が最初に集合を初期化すればよいか分からない。 この状況を避けるには、 \fBsemctl\fP(2)
159+の \fBIPC_STAT\fP 操作で取得できるセマフォのデータ構造体の \fIsem_otime\fP が 0 以外になっているかをチェックすればよい。
160+.SS セマフォの上限
161+セマフォ集合のリソースに関する上限のうち、 \fBsemget\fP() に影響を及ぼすものを以下に挙げる:
162+.TP
163+\fBSEMMNI\fP
164+.\" commit e843e7d2c88b7db107a86bd2c7145dc715c058f4
165+.\" This /proc file is not available in Linux 2.2 and earlier -- MTK
166+System\-wide limit on the number of semaphore sets. On Linux systems before
167+version 3.19, the default value for this limit was 128. Since Linux 3.19,
168+the default value is 32,000. On Linux, this limit can be read and modified
169+via the fourth field of \fI/proc/sys/kernel/sem\fP.
170+.TP
171+\fBSEMMSL\fP
172+.\" commit e843e7d2c88b7db107a86bd2c7145dc715c058f4
173+Maximum number of semaphores per semaphore ID. On Linux systems before
174+version 3.19, the default value for this limit was 250. Since Linux 3.19,
175+the default value is 32,000. On Linux, this limit can be read and modified
176+via the first field of \fI/proc/sys/kernel/sem\fP.
177+.TP
178+\fBSEMMNS\fP
179+システム全体のセマフォ数の上限値: 方針依存 (Linux では、この上限値は \fI/proc/sys/kernel/sem\fP の第 2
180+フィールドであり、読み出しも変更もできる)。 システム全体のセマフォ数には、 \fBSEMMSL\fP と \fBSEMMNI\fP の積という上限もある。
181+.SH バグ
182+\fBIPC_PRIVATE\fP という名前を選んだのはおそらく失敗であろう。 \fBIPC_NEW\fP の方がより明確にその機能を表しているだろう。
183+.SH 例
184+The program shown below uses \fBsemget\fP() to create a new semaphore set or
185+retrieve the ID of an existing set. It generates the \fIkey\fP for \fBsemget\fP()
186+using \fBftok\fP(3). The first two command\-line arguments are used as the
187+\fIpathname\fP and \fIproj_id\fP arguments for \fBftok\fP(3). The third command\-line
188+argument is an integer that specifies the \fInsems\fP argument for
189+\fBsemget\fP(). Command\-line options can be used to specify the \fBIPC_CREAT\fP
190+(\fI\-c\fP) and \fBIPC_EXCL\fP (\fI\-x\fP) flags for the call to \fBsemget\fP(). The
191+usage of this program is demonstrated below.
192+.PP
193+We first create two files that will be used to generate keys using
194+\fBftok\fP(3), create two semaphore sets using those files, and then list the
195+sets using \fBipcs\fP(1):
196+.PP
197+.in +4n
198+.EX
199+$ \fBtouch mykey mykey2\fP
200+$ \fB./t_semget \-c mykey p 1\fP
201+ID = 9
202+$ \fB./t_semget \-c mykey2 p 2\fP
203+ID = 10
204+$ \fBipcs \-s\fP
205+
206+\-\-\-\-\-\- Semaphore Arrays \-\-\-\-\-\-\-\-
207+key semid owner perms nsems
208+0x7004136d 9 mtk 600 1
209+0x70041368 10 mtk 600 2
210+.EE
211+.in
212+.PP
213+Next, we demonstrate that when \fBsemctl\fP(2) is given the same \fIkey\fP (as
214+generated by the same arguments to \fBftok\fP(3)), it returns the ID of the
215+already existing semaphore set:
216+.PP
217+.in +4n
218+.EX
219+$ \fB./t_semget \-c mykey p 1\fP
220+ID = 9
221+.EE
222+.in
223+.PP
224+Finally, we demonstrate the kind of collision that can occur when \fBftok\fP(3)
225+is given different \fIpathname\fP arguments that have the same inode number:
226+.PP
227+.in +4n
228+.EX
229+$ \fBln mykey link\fP
230+$ \fBls \-i1 link mykey\fP
231+2233197 link
232+2233197 mykey
233+$ \fB./t_semget link p 1\fP # Generates same key as \(aqmykey\(aq
234+ID = 9
235+.EE
236+.in
237+.SS プログラムのソース
238+\&
239+.EX
240+/* t_semget.c
241+
242+ Licensed under GNU General Public License v2 or later.
243+*/
244+#include <sys/types.h>
245+#include <sys/ipc.h>
246+#include <sys/sem.h>
247+#include <sys/stat.h>
248+#include <stdio.h>
249+#include <stdlib.h>
250+#include <unistd.h>
251+
252+static void
253+usage(const char *pname)
254+{
255+ fprintf(stderr, "Usage: %s [\-cx] pathname proj\-id num\-sems\en",
256+ pname);
257+ fprintf(stderr, " \-c Use IPC_CREAT flag\en");
258+ fprintf(stderr, " \-x Use IPC_EXCL flag\en");
259+ exit(EXIT_FAILURE);
260+}
261+
262+int
263+main(int argc, char *argv[])
264+{
265+ int semid, nsems, flags, opt;
266+ key_t key;
267+
268+ flags = 0;
269+ while ((opt = getopt(argc, argv, "cx")) != \-1) {
270+ switch (opt) {
271+ case \(aqc\(aq: flags |= IPC_CREAT; break;
272+ case \(aqx\(aq: flags |= IPC_EXCL; break;
273+ default: usage(argv[0]);
274+ }
275+ }
276+
277+ if (argc != optind + 3)
278+ usage(argv[0]);
279+
280+ key = ftok(argv[optind], argv[optind + 1][0]);
281+ if (key == \-1) {
282+ perror("ftok");
283+ exit(EXIT_FAILURE);
284+ }
285+
286+ nsems = atoi(argv[optind + 2]);
287+
288+ semid = semget(key, nsems, flags | 0600);
289+ if (semid == \-1) {
290+ perror("semget");
291+ exit(EXIT_FAILURE);
292+ }
293+
294+ printf("ID = %d\en", semid);
295+
296+ exit(EXIT_SUCCESS);
297+}
298+.EE
299+.SH 関連項目
300+\fBsemctl\fP(2), \fBsemop\fP(2), \fBftok\fP(3), \fBcapabilities\fP(7),
301+\fBsem_overview\fP(7), \fBsysvipc\fP(7)
302+.SH この文書について
303+この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 5.10 の一部である。プロジェクトの説明とバグ報告に関する情報は
304+\%https://www.kernel.org/doc/man\-pages/ に書かれている。
--- a/manual/LDP_man-pages/draft/man2/semop.2
+++ b/manual/LDP_man-pages/draft/man2/semop.2
@@ -151,9 +151,8 @@ short sem_flg; /* 操作フラグ */
151151 \fItimeout\fP 引き数が NULL の場合、 \fBsemtimedop\fP() 関数の振る舞いは
152152 \fBsemop\fP() 関数と全く同じになる。
153153 .PP
154-Note that if \fBsemtimedop\fP() is interrupted by a signal, causing the call
155-to fail with the error \fBEINTR\fP, the contents of \fItimeout\fP are left
156-unchanged.
154+\fBsemtimedop\fP() がシグナルにより割り込まれた場合、呼び出しはエラー \fBEINTR\fP で失敗し、 \fItimeout\fP
155+の内容は変更されないままとなる点に注意すること。
157156 .SH 返り値
158157 成功した場合、 \fBsemop\fP() と \fBsemtimedop\fP() は 0 を返す。そうでなければ \-1 を返し、 エラーを示す
159158 \fIerrno\fP を設定する。
@@ -257,7 +256,7 @@ array.
257256 .\" http://marc.theaimsgroup.com/?l=linux-kernel&m=110261701025794&w=2
258257 カーネル 2.6.x (x <= 10) には、ある状況においてセマフォ値が 0 になるのを 待っているスレッドが、セマフォ値が実際に 0
259258 になったときに起床 (wake up) されない、というバグがある。このバグはカーネル 2.6.11 で修正されている。
260-.SH EXAMPLES
259+.SH 例
261260 以下の部分的なコードは、 セマフォ 0 の値が 0 になるのを待ってから、 セマフォの値を 1 加算する処理を、 \fBsemop\fP()
262261 を使ってアトミック (atomically) に行う。
263262 .PP
--- a/manual/LDP_man-pages/draft/man3/sem_getvalue.3
+++ b/manual/LDP_man-pages/draft/man3/sem_getvalue.3
@@ -45,11 +45,9 @@ sem_getvalue \- セマフォの値を取得する
4545 .SH 説明
4646 \fBsem_getvalue\fP() は、 \fIsem\fP が指すセマフォの現在の値を \fIsval\fP で指す整数に格納する。
4747 .PP
48-If one or more processes or threads are blocked waiting to lock the
49-semaphore with \fBsem_wait\fP(3), POSIX.1 permits two possibilities for the
50-value returned in \fIsval\fP: either 0 is returned; or a negative number whose
51-absolute value is the count of the number of processes and threads currently
52-blocked in \fBsem_wait\fP(3). Linux adopts the former behavior.
48+POSIX.1 によると、 1つ以上のプロセスかスレッドが \fBsem_wait\fP(3) でセマフォのロック待ちで停止している場合、 \fIsval\fP
49+で返される値は 0 もしくは負の値のいずれかとなる。 負の値の場合、その絶対値は \fBsem_wait\fP(3)
50+で現在停止しているプロセスかスレッドの合計数に等しい。 Linux は前者の動作 (0 を返す動作) を採用している。
5351 .SH 返り値
5452 成功すると、 \fBsem_getvalue\fP() は 0 を返す。エラーの場合、\-1 を返し、 \fIerrno\fP にエラーを示す値をセットする。
5553 .SH エラー
--- a/manual/LDP_man-pages/draft/man3/sem_init.3
+++ b/manual/LDP_man-pages/draft/man3/sem_init.3
@@ -83,8 +83,8 @@ POSIX.1\-2001.
8383 .SH 注意
8484 妙なことに、POSIX.1\-2001 は \fBsem_init\fP() が成功した場合に返すべき値を規定していない。 POSIX.1\-2008
8585 ではこれが修正され、成功時には 0 を返すことが規定された。
86-.SH EXAMPLES
87-See \fBshm_open\fP(3) and \fBsem_wait\fP(3).
86+.SH 例
87+\fBsem_open\fP(3) と \fBsem_wait\fP(3) を参照。
8888 .SH 関連項目
8989 \fBsem_destroy\fP(3), \fBsem_post\fP(3), \fBsem_wait\fP(3), \fBsem_overview\fP(7)
9090 .SH この文書について
--- a/manual/LDP_man-pages/draft/man3/sem_open.3
+++ b/manual/LDP_man-pages/draft/man3/sem_open.3
@@ -82,14 +82,13 @@ sem_open \- 名前付きセマフォを初期化し、オープンする
8282 \fIname\fP が "/" だけで構成され、その後ろに他の文字が続いていなかった。
8383 .TP
8484 \fBEMFILE\fP
85-The per\-process limit on the number of open file descriptors has been
86-reached.
85+オープンされたファイルディスクリプターの総数がプロセス単位の上限に達している。
8786 .TP
8887 \fBENAMETOOLONG\fP
8988 \fIname\fP が長すぎる。
9089 .TP
9190 \fBENFILE\fP
92-The system\-wide limit on the total number of open files has been reached.
91+オープンされたファイル総数がシステム全体での上限に達している。
9392 .TP
9493 \fBENOENT\fP
9594 .\" this error can occur if we have a name of the (nonportable) form
--- a/manual/LDP_man-pages/draft/man3/sem_post.3
+++ b/manual/LDP_man-pages/draft/man3/sem_post.3
@@ -71,8 +71,8 @@ T} Thread safety MT\-Safe
7171 POSIX.1\-2001.
7272 .SH 注意
7373 \fBsem_post\fP() は async\-signal\-safe である。 つまり、シグナルハンドラーの中でも安全に呼び出すことができる。
74-.SH EXAMPLES
75-See \fBsem_wait\fP(3) and \fBshm_open\fP(3).
74+.SH 例
75+\fBsem_wait\fP(3) と \fBsem_open\fP(3) を参照。
7676 .SH 関連項目
7777 \fBsem_getvalue\fP(3), \fBsem_wait\fP(3), \fBsem_overview\fP(7), \fBsignal\-safety\fP(7)
7878 .SH この文書について
--- a/manual/LDP_man-pages/draft/man3/sem_wait.3
+++ b/manual/LDP_man-pages/draft/man3/sem_wait.3
@@ -118,7 +118,7 @@ T} Thread safety MT\-Safe
118118 .TE
119119 .SH 準拠
120120 POSIX.1\-2001, POSIX.1\-2008.
121-.SH EXAMPLES
121+.SH 例
122122 以下に示す (ちょっとした) プログラムは名前なしセマフォの操作を行う。 プログラムはコマンドライン引き数を 2 つ取る。 最初の引き数には、
123123 \fBSIGALRM\fP シグナルを生成するためのアラームタイマーの設定に使われる値を 秒単位で指定する。このシグナルハンドラーは、 \fImain()\fP
124124 内で \fBsem_timedwait\fP() を使って待っているセマフォを、 \fBsem_post\fP(3) を使って加算する。 2番目の引き数には、
--- a/manual/LDP_man-pages/draft/man7/sem_overview.7
+++ b/manual/LDP_man-pages/draft/man7/sem_overview.7
@@ -98,7 +98,7 @@ Linux 2.6.19 以降では、このディレクトリ配下のファイルに対
9898 System V セマフォ (\fBsemget\fP(2), \fBsemop\fP(2) など) は古いセマフォ API である。 POSIX セマフォは
9999 System V よりも 簡単で、うまく設計されたインターフェースを提供している。 一方で、POSIX セマフォは System V セマフォと比べると
100100 利用できるシステムが少ない (特に、古いシステムでは少ない)。
101-.SH EXAMPLES
101+.SH 例
102102 各種の POSIX セマフォ関数を使用した例が \fBsem_wait\fP(3) に記載されている。
103103 .SH 関連項目
104104 \fBsem_close\fP(3), \fBsem_destroy\fP(3), \fBsem_getvalue\fP(3), \fBsem_init\fP(3),
Show on old repository browser