1 .\" Copyright 1993 Giorgio Ciucci (giorgio@crcc.it)
3 .\" Permission is granted to make and distribute verbatim copies of this
4 .\" manual provided the copyright notice and this permission notice are
5 .\" preserved on all copies.
7 .\" Permission is granted to copy and distribute modified versions of this
8 .\" manual under the conditions for verbatim copying, provided that the
9 .\" entire resulting derived work is distributed under the terms of a
10 .\" permission notice identical to this one.
12 .\" Since the Linux kernel and libraries are constantly changing, this
13 .\" manual page may be incorrect or out-of-date. The author(s) assume no
14 .\" responsibility for errors or omissions, or for damages resulting from
15 .\" the use of the information contained herein. The author(s) may not
16 .\" have taken the same level of care in the production of this manual,
17 .\" which is licensed free of charge, as they might when working
20 .\" Formatted or processed versions of this manual, if unaccompanied by
21 .\" the source, must acknowledge the copyright and authors of this work.
23 .\" Modified Tue Oct 22 17:54:56 1996 by Eric S. Raymond <esr@thyrsus.com>
24 .\" Modified 1 Jan 2002, Martin Schulze <joey@infodrom.org>
25 .\" Modified 4 Jan 2002, Michael Kerrisk <mtk.manpages@gmail.com>
26 .\" Modified, 27 May 2004, Michael Kerrisk <mtk.manpages@gmail.com>
27 .\" Added notes on capability requirements
28 .\" Modified, 11 Nov 2004, Michael Kerrisk <mtk.manpages@gmail.com>
29 .\" Language and formatting clean-ups
30 .\" Added notes on /proc files
31 .\" Rewrote BUGS note about semget()'s failure to initialize
34 .\" Japanese Version Copyright (c) 1997 HANATAKA Shinya
35 .\" all rights reserved.
36 .\" Translated 1997-02-23, HANATAKA Shinya <hanataka@abyss.rim.or.jp>
37 .\" Updated 2003-04-08, Kentaro Shirakata <argrath@ub32.org>
38 .\" Updated 2005-03-01, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
39 .\" Updated 2006-07-20, Akihiro MOTOKI, LDP v2.36
41 .\"WORD: semaphore セマフォ
42 .\"WORD: identifier 識別子
46 .\"WORD: effective user ID 実効ユーザー ID
47 .\"WORD: effective group ID 実効グループ ID
48 .\"WORD: calling process 呼び出し元のプロセス
51 .\"WORD: structure 構造体
52 .\"WORD: initialize 初期化
53 .\"WORD: system call システム・コール
55 .TH SEMGET 2 2004-05-27 "Linux" "Linux Programmer's Manual"
58 .\"O semget \- get a semaphore set identifier
59 semget \- セマフォ集合の識別子を取得する
63 .B #include <sys/types.h>
64 .B #include <sys/ipc.h>
65 .B #include <sys/sem.h>
68 .BI "int semget(key_t " key ,
75 .\"O system call returns the semaphore set identifier
76 .\"O associated with the argument
81 に対応するセマフォ集合 (semaphore set) の
85 .\"O semaphores is created if
89 .\"O or if no existing semaphore set is associated with
106 個のセマフォからなる新しい集合が作成される。
114 .\"O and a semaphore set already exists for
122 .\"O (This is analogous to the effect of the combination
123 .\"O .B O_CREAT | O_EXCL
146 .\"O Upon creation, the least significant 9 bits of the argument
148 .\"O define the permissions (for owner, group and others)
149 .\"O for the semaphore set.
150 .\"O These bits have the same format, and the same
155 .\"O (though the execute permissions are
156 .\"O not meaningful for semaphores, and write permissions mean permission
157 .\"O to alter semaphore values).
160 の下位 9 ビットは、そのセマフォ集合の (所有者 (owner)、グループ (group)、
161 他人 (others) に対する) アクセス許可の定義として使用される。
167 (但し、実行 (execute) 許可はセマフォでは意味を持たず、
168 書き込み (write) 許可はセマフォ値の変更 (alter) 許可として機能する)。
170 .\"O The values of the semaphores in a newly created set are indeterminate.
171 .\"O (POSIX.1-2001 is explicit on this point.)
172 .\"O Although Linux, like many other implementations,
173 .\"O initializes the semaphore values to 0,
174 .\"O a portable application cannot rely on this:
175 .\"O it should explicitly initialize the semaphores to the desired values.
176 新しく作成されたセマフォ集合の各セマフォの値は不定である
177 (この点は POSIX.1-2001 に明記されている)。
178 Linux は他の多くの実装と同様にセマフォ値を 0 に初期化するが、
179 移植性を考慮したアプリケーションではこの動作を前提にすべきではない。
180 アプリケーションは明示的にセマフォを希望の値で初期化すべきである。
181 .\" In truth, every one of the many implementations that I've tested sets
182 .\" the values to zero, but I suppose there is/was some obscure
183 .\" implementation out there that does not.
185 .\"O When creating a new semaphore set,
187 .\"O initializes the set's associated data structure,
190 .\"O .BR semctl (2)),
194 はセマフォ集合の情報を保持するデータ構造体
202 .\"O .I sem_perm.cuid
205 .\"O are set to the effective user ID of the calling process.
209 に、呼び出し元のプロセスの実効 (effective) ユーザ ID を設定する。
211 .\"O .I sem_perm.cgid
214 .\"O are set to the effective group ID of the calling process.
218 に、呼び出し元のプロセスの実効 (effective) グループ ID を設定する。
220 .\"O The least significant 9 bits of
221 .\"O .I sem_perm.mode
222 .\"O are set to the least significant 9 bits of
230 .\"O is set to the value of
243 .\"O is set to the current time.
251 .\"O when a semaphore set is not being created.
254 .\"O must be greater than 0
255 .\"O and less than or equal to the maximum number of semaphores per semaphore set
257 セマフォ集合の作成を行わない場合は、引き数
259 に (don't care を意味する) 0 を指定してもよい。
262 は 0 より大きい値でなければならず、セマフォ集合あたりのセマフォの最大数
266 .\"O If the semaphore set already exists, the permissions are
268 セマフォ集合が既に存在した場合は、アクセス許可の検査が行われる。
269 .\"O .\" and a check is made to see if it is marked for destruction.
270 .\" 破壊 (destruction) マークがないかチェックされる。
271 .\"O .SH "RETURN VALUE"
273 .\"O If successful, the return value will be the semaphore set identifier
274 .\"O (a nonnegative integer), otherwise \-1
275 .\"O is returned, with
277 .\"O indicating the error.
278 成功した場合、セマフォ集合の識別子 (非負の整数) が返り値となる。
286 .\"O will be set to one of the following:
292 .\"O A semaphore set exists for
294 .\"O but the calling process does not have permission to access the set,
295 .\"O and does not have the
296 .\"O .B CAP_IPC_OWNER
300 呼び出し元のプロセスはその集合へのアクセス許可がなく、
305 .\"O A semaphore set exists for
323 .\"O .\" The semaphore set is marked to be deleted.
325 .\" セマフォ集合に削除 (delete) マークがつけられている。
329 .\"O is less than 0 or greater than the limit on the number
330 .\"O of semaphores per semaphore set
333 が 0 より小さいか、セマフォ集合あたりのセマフォの最大数
336 .\"O or a semaphore set corresponding to
338 .\"O already exists, and
340 .\"O is larger than the number of semaphores in that set.
348 .\"O No semaphore set exists for
362 .\"O A semaphore set has to be created but the system does not have
363 .\"O enough memory for the new data structure.
364 セマフォ集合を作成しようとしたが、新しいデータ構造体を
365 作成するのに十分なメモリがシステムに存在しない。
368 .\"O A semaphore set has to be created but the system limit for the maximum
369 .\"O number of semaphore sets
371 .\"O or the system wide maximum number of semaphores
373 .\"O would be exceeded.
374 セマフォ集合を作成しようとすると、システムのセマフォ集合の
380 .\"O .SH "CONFORMING TO"
383 .\"O .\" SVr4 documents additional error conditions EFBIG, E2BIG, EAGAIN,
384 .\"O .\" ERANGE, EFAULT.
385 .\" SVr4 には、追加で EFBIG, E2BIG, EAGAIN, ERANGE, EFAULT
386 .\" のエラー状態についての記述がある。
390 .\"O isn't a flag field but a
394 はフラグ・フィールドに指定するものではなく、
397 .\"O If this special value is used for
399 .\"O the system call ignores everything but the least significant 9 bits of
401 .\"O and creates a new semaphore set (on success).
408 (成功した場合は) 新しいセマフォ集合を作成する。
410 .\"O The following limits on semaphore set resources affect the
413 セマフォ集合のリソースに関する制限のうち、
418 .\"O System wide maximum number of semaphore sets: policy dependent
419 .\"O (on Linux, this limit can be read and modified via the fourth field of
420 .\"O .IR /proc/sys/kernel/sem ).
421 .\"O .\" This /proc file is not available in Linux 2.2 and earlier -- MTK
422 システム全体のセマフォ集合の最大数: 方針依存
424 .I /proc/sys/kernel/sem
425 の第4フィールドに対応し、読み出しも変更もできる)。
426 .\" この /proc ファイルは Linux 2.2 以前では利用できない -- MTK
429 .\"O Maximum number of semaphores per semid: implementation dependent
430 .\"O (on Linux, this limit can be read and modified via the first field of
431 .\"O .IR /proc/sys/kernel/sem ).
432 semid あたりのセマフォの最大数: 実装依存
434 .I /proc/sys/kernel/sem
435 の第1フィールドに対応し、読み出しも変更もできる)。
438 .\"O System wide maximum number of semaphores: policy dependent
439 .\"O (on Linux, this limit can be read and modified via the second field of
440 .\"O .IR /proc/sys/kernel/sem ).
441 .\"O Values greater than
442 .\"O .B SEMMSL * SEMMNI
443 .\"O makes it irrelevant.
444 システム全体のセマフォの最大数: 方針依存
446 .I /proc/sys/kernel/sem
447 の第2フィールドに対応し、読み出しも変更もできる)。
454 .\"O was perhaps unfortunate,
456 .\"O would more clearly show its function.
458 という名前を選んだのはおそらく失敗であろう。
460 の方がより明確にその機能を表しているだろう。
462 .\"O The semaphores in a set are not initialized by
464 .\"O .\" In fact they are initialized to zero on Linux, but POSIX.1-2001
465 .\"O .\" does not specify this, and we can't portably rely on it.
466 .\"O In order to initialize the semaphores,
468 .\"O must be used to perform a
472 .\"O operation on the semaphore set.
476 .\" 実際は Linux ではセマフォは 0 に初期化されるが、
477 .\" POSIX.1-2001 ではこうなることを規定している訳ではないので、
478 .\" 移植を考慮するときにはこれを前提にしてはいけない。
479 このセマフォを初期化するには、セマフォ集合に対して
486 .\"O (Where multiple peers do not know who will be the first to
487 .\"O initialize the set, checking for a nonzero
489 .\"O in the associated data structure retrieved by a
492 .\"O operation can be used to avoid races.)
493 (複数箇所からセマフォ集合の操作が行われる場面では、
494 誰が最初に集合を初期化すればよいか分からない。
501 が 0 以外になっているかをチェックすればよい。)
507 .BR capabilities (7),
508 .BR sem_overview (7),