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"
57 semget \- セマフォ集合の識別子を取得する
60 .B #include <sys/types.h>
61 .B #include <sys/ipc.h>
62 .B #include <sys/sem.h>
65 .BI "int semget(key_t " key ,
72 に対応するセマフォ集合 (semaphore set) の
85 個のセマフォからなる新しい集合が作成される。
109 の下位 9 ビットは、そのセマフォ集合の (所有者 (owner)、グループ (group)、
110 他人 (others) に対する) アクセス許可の定義として使用される。
116 (但し、実行 (execute) 許可はセマフォでは意味を持たず、
117 書き込み (write) 許可はセマフォ値の変更 (alter) 許可として機能する)。
119 新しく作成されたセマフォ集合の各セマフォの値は不定である
120 (この点は POSIX.1-2001 に明記されている)。
121 Linux は他の多くの実装と同様にセマフォ値を 0 に初期化するが、
122 移植性を考慮したアプリケーションではこの動作を前提にすべきではない。
123 アプリケーションは明示的にセマフォを希望の値で初期化すべきである。
124 .\" In truth, every one of the many implementations that I've tested sets
125 .\" the values to zero, but I suppose there is/was some obscure
126 .\" implementation out there that does not.
130 はセマフォ集合の情報を保持するデータ構造体
141 に、呼び出し元のプロセスの実効 (effective) ユーザ ID を設定する。
146 に、呼び出し元のプロセスの実効 (effective) グループ ID を設定する。
164 セマフォ集合の作成を行わない場合は、引き数
166 に (don't care を意味する) 0 を指定してもよい。
169 は 0 より大きい値でなければならず、セマフォ集合あたりのセマフォの最大数
173 セマフォ集合が既に存在した場合は、アクセス許可の検査が行われる。
174 .\" 破壊 (destruction) マークがないかチェックされる。
176 成功した場合、セマフォ集合の識別子 (非負の整数) が返り値となる。
188 呼び出し元のプロセスはその集合へのアクセス許可がなく、
203 .\" セマフォ集合に削除 (delete) マークがつけられている。
207 が 0 より小さいか、セマフォ集合あたりのセマフォの最大数
225 セマフォ集合を作成しようとしたが、新しいデータ構造体を
226 作成するのに十分なメモリがシステムに存在しない。
229 セマフォ集合を作成しようとすると、システムのセマフォ集合の
237 .\" SVr4 には、追加で EFBIG, E2BIG, EAGAIN, ERANGE, EFAULT
238 .\" のエラー状態についての記述がある。
241 はフラグ・フィールドに指定するものではなく、
250 (成功した場合は) 新しいセマフォ集合を作成する。
252 セマフォ集合のリソースに関する制限のうち、
257 システム全体のセマフォ集合の最大数: 方針依存
259 .I /proc/sys/kernel/sem
260 の第4フィールドに対応し、読み出しも変更もできる)。
261 .\" この /proc ファイルは Linux 2.2 以前では利用できない -- MTK
264 semid あたりのセマフォの最大数: 実装依存
266 .I /proc/sys/kernel/sem
267 の第1フィールドに対応し、読み出しも変更もできる)。
270 システム全体のセマフォの最大数: 方針依存
272 .I /proc/sys/kernel/sem
273 の第2フィールドに対応し、読み出しも変更もできる)。
278 という名前を選んだのはおそらく失敗であろう。
280 の方がより明確にその機能を表しているだろう。
285 .\" 実際は Linux ではセマフォは 0 に初期化されるが、
286 .\" POSIX.1-2001 ではこうなることを規定している訳ではないので、
287 .\" 移植を考慮するときにはこれを前提にしてはいけない。
288 このセマフォを初期化するには、セマフォ集合に対して
295 (複数箇所からセマフォ集合の操作が行われる場面では、
296 誰が最初に集合を初期化すればよいか分からない。
303 が 0 以外になっているかをチェックすればよい。)
308 .BR capabilities (7),
309 .BR sem_overview (7),