OSDN Git Service

(split) LDP: draft snapshot generated from latest ja.po files.
[linuxjm/LDP_man-pages.git] / draft / man2 / semget.2
1 .\" Copyright 1993 Giorgio Ciucci (giorgio@crcc.it)
2 .\"
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.
6 .\"
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.
11 .\"
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
18 .\" professionally.
19 .\"
20 .\" Formatted or processed versions of this manual, if unaccompanied by
21 .\" the source, must acknowledge the copyright and authors of this work.
22 .\"
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
32 .\"             semaphore values
33 .\"
34 .\"*******************************************************************
35 .\"
36 .\" This file was generated with po4a. Translate the source file.
37 .\"
38 .\"*******************************************************************
39 .TH SEMGET 2 2004\-05\-27 Linux "Linux Programmer's Manual"
40 .SH 名前
41 semget \- セマフォ集合の識別子を取得する
42 .SH 書式
43 .nf
44 \fB#include <sys/types.h>\fP
45 \fB#include <sys/ipc.h>\fP
46 \fB#include <sys/sem.h>\fP
47 .fi
48 .sp
49 \fBint semget(key_t \fP\fIkey\fP\fB,\fP \fBint \fP\fInsems\fP\fB,\fP \fBint \fP\fIsemflg\fP\fB);\fP
50 .SH 説明
51 \fBsemget\fP()  システムコールは、引き数 \fIkey\fP に対応するセマフォ集合 (semaphore set) の 識別子
52 (identifier) を返す。 \fIkey\fP の値が \fBIPC_PRIVATE\fP の場合、もしくは \fIsemflg\fP に
53 \fBIPC_CREAT\fP が指定されていて、 \fIkey\fP に対応するセマフォ集合が存在しない場合、 \fInsems\fP
54 個のセマフォからなる新しい集合が作成される。
55 .PP
56 \fIsemflg\fP に \fBIPC_CREAT\fP と \fBIPC_EXCL\fP の両方が指定された場合、 \fIkey\fP
57 に対応するセマフォ集合が既に存在すると、 \fBsemget\fP()  は失敗し、 \fIerrno\fP に \fBEEXIST\fP が設定される (これは
58 \fBopen\fP(2)  に \fBO_CREAT | O_EXCL\fP が指定された場合の動作と同じである)。
59 .PP
60 セマフォ集合作成時に、引き数 \fIsemflg\fP の下位 9 ビットは、そのセマフォ集合の (所有者 (owner)、グループ (group)、 他人
61 (others) に対する) アクセス許可の定義として使用される。 これらのビットは \fBopen\fP(2)  の引き数 \fImode\fP
62 と同じ形式で同じ意味である (但し、実行 (execute) 許可はセマフォでは意味を持たず、 書き込み (write) 許可はセマフォ値の変更
63 (alter) 許可として機能する)。
64 .PP
65 .\" In truth, every one of the many implementations that I've tested sets
66 .\" the values to zero, but I suppose there is/was some obscure
67 .\" implementation out there that does not.
68 新しく作成されたセマフォ集合の各セマフォの値は不定である (この点は POSIX.1\-2001 に明記されている)。 Linux
69 は他の多くの実装と同様にセマフォ値を 0 に初期化するが、 移植性を考慮したアプリケーションではこの動作を前提にすべきではない。
70 アプリケーションは明示的にセマフォを希望の値で初期化すべきである。
71 .PP
72 新規のセマフォ集合を作成する際、 \fBsemget\fP()  はセマフォ集合の情報を保持するデータ構造体 \fIsemid_ds\fP を次のように初期化する
73 (\fIsemid_ds\fP については \fBsemctl\fP(2)  を参照):
74 .IP
75 \fIsem_perm.cuid\fP と \fIsem_perm.uid\fP に、呼び出し元のプロセスの実効 (effective) ユーザ ID を設定する。
76 .IP
77 \fIsem_perm.cgid\fP と \fIsem_perm.gid\fP に、呼び出し元のプロセスの実効 (effective) グループ ID
78 を設定する。
79 .IP
80 \fIsem_perm.mode\fP の下位 9 ビットに \fIsemflg\fP の下位 9 ビットを設定する。
81 .IP
82 \fIsem_nsems\fP に \fInsems\fP の値を設定する。
83 .IP
84 \fIsem_otime\fP に 0 を設定する。
85 .IP
86 \fIsem_ctime\fP に現在の時刻を設定する。
87 .PP
88 セマフォ集合の作成を行わない場合は、引き数 \fInsems\fP に (don't care を意味する) 0 を指定してもよい。 そうでない場合は、
89 \fInsems\fP は 0 より大きい値でなければならず、セマフォ集合あたりのセマフォの最大数 (\fBSEMMSL\fP)  以下でなければならない。
90 .PP
91 .\" and a check is made to see if it is marked for destruction.
92 セマフォ集合が既に存在した場合は、アクセス許可の検査が行われる。
93 .SH 返り値
94 成功した場合、セマフォ集合の識別子 (非負の整数) が返り値となる。 失敗した場合は \-1 が返され、 \fIerrno\fP にエラーを示す値が設定される。
95 .SH エラー
96 失敗した場合、 \fIerrno\fP には以下の値のいずれか一つが設定される:
97 .TP 
98 \fBEACCES\fP
99 \fIkey\fP に対応するセマフォ集合は存在するが、 呼び出し元のプロセスはその集合へのアクセス許可がなく、 \fBCAP_IPC_OWNER\fP
100 ケーパビリティも持っていない。
101 .TP 
102 \fBEEXIST\fP
103 .\" .TP
104 .\" .B EIDRM
105 .\" The semaphore set is marked to be deleted.
106 \fIkey\fP に対応するセマフォ集合が存在し、 \fIsemflg\fP には \fBIPC_CREAT\fP と \fBIPC_EXCL\fP が指定されていた。
107 .TP 
108 \fBEINVAL\fP
109 \fInsems\fP が 0 より小さいか、セマフォ集合あたりのセマフォの最大数 (\fBSEMMSL\fP)  より大きい。 または、 \fIkey\fP
110 に対応するセマフォ集合が既に存在し、 \fInsems\fP がその集合のセマフォ数よりも大きい。
111 .TP 
112 \fBENOENT\fP
113 \fIkey\fP に対応するセマフォ集合が存在せず、 \fIsemflg\fP に \fBIPC_CREAT\fP が指定されてもいない。
114 .TP 
115 \fBENOMEM\fP
116 セマフォ集合を作成しようとしたが、新しいデータ構造体を 作成するのに十分なメモリがシステムに存在しない。
117 .TP 
118 \fBENOSPC\fP
119 セマフォ集合を作成しようとすると、システムのセマフォ集合の 最大数 (\fBSEMMNI\fP)  か、システム全体のセマフォの最大数 (\fBSEMMNS\fP)
120 のいずれかを超えてしまう。
121 .SH 準拠
122 .\" SVr4 documents additional error conditions EFBIG, E2BIG, EAGAIN,
123 .\" ERANGE, EFAULT.
124 SVr4, POSIX.1\-2001.
125 .SH 注意
126 \fBIPC_PRIVATE\fP はフラグ・フィールドに指定するものではなく、 \fIkey_t\fP 型である。 この特別な値が \fIkey\fP に指定されると、
127 \fBsemget\fP()  \fIsemflg\fP の下位 9 ビット以外は全て無視し、 (成功した場合は) 新しいセマフォ集合を作成する。
128 .PP
129 セマフォ集合のリソースに関する制限のうち、 \fBsemget\fP()  に影響を及ぼすものを以下に挙げる:
130 .TP 
131 \fBSEMMNI\fP
132 .\" This /proc file is not available in Linux 2.2 and earlier -- MTK
133 システム全体のセマフォ集合の最大数: 方針依存 (Linux では、この制限値は \fI/proc/sys/kernel/sem\fP
134 の第4フィールドに対応し、読み出しも変更もできる)。
135 .TP 
136 \fBSEMMSL\fP
137 semid あたりのセマフォの最大数: 実装依存 (Linux では、この制限値は \fI/proc/sys/kernel/sem\fP
138 の第1フィールドに対応し、読み出しも変更もできる)。
139 .TP 
140 \fBSEMMNS\fP
141 システム全体のセマフォの最大数: 方針依存 (Linux では、この制限値は \fI/proc/sys/kernel/sem\fP
142 の第2フィールドに対応し、読み出しも変更もできる)。 \fBSEMMSL * SEMMNI\fP より大きな値は意味を持たない。
143 .SH バグ
144 \fBIPC_PRIVATE\fP という名前を選んだのはおそらく失敗であろう。 \fBIPC_NEW\fP の方がより明確にその機能を表しているだろう。
145 .LP
146 .\" In fact they are initialized to zero on Linux, but POSIX.1-2001
147 .\" does not specify this, and we can't portably rely on it.
148 セマフォ集合内のセマフォは \fBsemget\fP()  では初期化されない。 このセマフォを初期化するには、セマフォ集合に対して \fBsemctl\fP(2)
149 を使って \fBSETVAL\fP か \fBSETALL\fP 操作を実行する必要がある。 (複数箇所からセマフォ集合の操作が行われる場面では、
150 誰が最初に集合を初期化すればよいか分からない。 この状況を避けるには、 \fBsemctl\fP(2)  の \fBIPC_STAT\fP
151 操作で取得できるセマフォのデータ構造体の \fIsem_otime\fP が 0 以外になっているかをチェックすればよい。)
152 .SH 関連項目
153 \fBsemctl\fP(2), \fBsemop\fP(2), \fBftok\fP(3), \fBcapabilities\fP(7),
154 \fBsem_overview\fP(7), \fBsvipc\fP(7)