OSDN Git Service

(split) DP: release pages (catch up to 3.50).
[linuxjm/LDP_man-pages.git] / release / man2 / semget.2
1 .\" Copyright 1993 Giorgio Ciucci (giorgio@crcc.it)
2 .\"
3 .\" %%%LICENSE_START(VERBATIM)
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
7 .\"
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
12 .\"
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein.  The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
19 .\" professionally.
20 .\"
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
23 .\" %%%LICENSE_END
24 .\"
25 .\" Modified Tue Oct 22 17:54:56 1996 by Eric S. Raymond <esr@thyrsus.com>
26 .\" Modified 1 Jan 2002, Martin Schulze <joey@infodrom.org>
27 .\" Modified 4 Jan 2002, Michael Kerrisk <mtk.manpages@gmail.com>
28 .\" Modified, 27 May 2004, Michael Kerrisk <mtk.manpages@gmail.com>
29 .\"     Added notes on capability requirements
30 .\" Modified, 11 Nov 2004, Michael Kerrisk <mtk.manpages@gmail.com>
31 .\"     Language and formatting clean-ups
32 .\"     Added notes on /proc files
33 .\"     Rewrote BUGS note about semget()'s failure to initialize
34 .\"             semaphore values
35 .\"
36 .\"*******************************************************************
37 .\"
38 .\" This file was generated with po4a. Translate the source file.
39 .\"
40 .\"*******************************************************************
41 .TH SEMGET 2 2012\-05\-31 Linux "Linux Programmer's Manual"
42 .SH 名前
43 semget \- セマフォ集合の識別子を取得する
44 .SH 書式
45 .nf
46 \fB#include <sys/types.h>\fP
47 \fB#include <sys/ipc.h>\fP
48 \fB#include <sys/sem.h>\fP
49 .fi
50 .sp
51 \fBint semget(key_t \fP\fIkey\fP\fB,\fP \fBint \fP\fInsems\fP\fB,\fP \fBint \fP\fIsemflg\fP\fB);\fP
52 .SH 説明
53 \fBsemget\fP()  システムコールは、引き数 \fIkey\fP に対応するセマフォ集合 (semaphore set) の 識別子
54 (identifier) を返す。 \fIkey\fP の値が \fBIPC_PRIVATE\fP の場合、もしくは \fIsemflg\fP に
55 \fBIPC_CREAT\fP が指定されていて、 \fIkey\fP に対応するセマフォ集合が存在しない場合、 \fInsems\fP
56 個のセマフォからなる新しい集合が作成される。
57 .PP
58 \fIsemflg\fP に \fBIPC_CREAT\fP と \fBIPC_EXCL\fP の両方が指定された場合、 \fIkey\fP
59 に対応するセマフォ集合が既に存在すると、 \fBsemget\fP()  は失敗し、 \fIerrno\fP に \fBEEXIST\fP が設定される (これは
60 \fBopen\fP(2)  に \fBO_CREAT | O_EXCL\fP が指定された場合の動作と同じである)。
61 .PP
62 セマフォ集合作成時に、引き数 \fIsemflg\fP の下位 9 ビットは、そのセマフォ集合の (所有者 (owner)、グループ (group)、 他人
63 (others) に対する) アクセス許可の定義として使用される。 これらのビットは \fBopen\fP(2)  の引き数 \fImode\fP
64 と同じ形式で同じ意味である (但し、実行 (execute) 許可はセマフォでは意味を持たず、 書き込み (write) 許可はセマフォ値の変更
65 (alter) 許可として機能する)。
66 .PP
67 .\" In truth, every one of the many implementations that I've tested sets
68 .\" the values to zero, but I suppose there is/was some obscure
69 .\" implementation out there that does not.
70 新しく作成されたセマフォ集合の各セマフォの値は不定である (この点は POSIX.1\-2001 に明記されている)。 Linux
71 は他の多くの実装と同様にセマフォ値を 0 に初期化するが、 移植性を考慮したアプリケーションではこの動作を前提にすべきではない。
72 アプリケーションは明示的にセマフォを希望の値で初期化すべきである。
73 .PP
74 新規のセマフォ集合を作成する際、 \fBsemget\fP()  はセマフォ集合の情報を保持するデータ構造体 \fIsemid_ds\fP を次のように初期化する
75 (\fIsemid_ds\fP については \fBsemctl\fP(2)  を参照):
76 .IP
77 \fIsem_perm.cuid\fP と \fIsem_perm.uid\fP に、呼び出し元のプロセスの実効 (effective) ユーザ ID を設定する。
78 .IP
79 \fIsem_perm.cgid\fP と \fIsem_perm.gid\fP に、呼び出し元のプロセスの実効 (effective) グループ ID
80 を設定する。
81 .IP
82 \fIsem_perm.mode\fP の下位 9 ビットに \fIsemflg\fP の下位 9 ビットを設定する。
83 .IP
84 \fIsem_nsems\fP に \fInsems\fP の値を設定する。
85 .IP
86 \fIsem_otime\fP に 0 を設定する。
87 .IP
88 \fIsem_ctime\fP に現在の時刻を設定する。
89 .PP
90 セマフォ集合の作成を行わない場合は、引き数 \fInsems\fP に (don't care を意味する) 0 を指定してもよい。 そうでない場合は、
91 \fInsems\fP は 0 より大きい値でなければならず、セマフォ集合あたりのセマフォの最大数 (\fBSEMMSL\fP)  以下でなければならない。
92 .PP
93 .\" and a check is made to see if it is marked for destruction.
94 セマフォ集合が既に存在した場合は、アクセス許可の検査が行われる。
95 .SH 返り値
96 成功した場合、セマフォ集合の識別子 (非負の整数) が返り値となる。 失敗した場合は \-1 が返され、 \fIerrno\fP にエラーを示す値が設定される。
97 .SH エラー
98 失敗した場合、 \fIerrno\fP には以下の値のいずれか一つが設定される:
99 .TP 
100 \fBEACCES\fP
101 \fIkey\fP に対応するセマフォ集合は存在するが、 呼び出し元のプロセスはその集合へのアクセス許可がなく、 \fBCAP_IPC_OWNER\fP
102 ケーパビリティも持っていない。
103 .TP 
104 \fBEEXIST\fP
105 .\" .TP
106 .\" .B EIDRM
107 .\" The semaphore set is marked to be deleted.
108 \fIkey\fP に対応するセマフォ集合が存在し、 \fIsemflg\fP には \fBIPC_CREAT\fP と \fBIPC_EXCL\fP が指定されていた。
109 .TP 
110 \fBEINVAL\fP
111 \fInsems\fP が 0 より小さいか、セマフォ集合あたりのセマフォの最大数 (\fBSEMMSL\fP)  より大きい。 または、 \fIkey\fP
112 に対応するセマフォ集合が既に存在し、 \fInsems\fP がその集合のセマフォ数よりも大きい。
113 .TP 
114 \fBENOENT\fP
115 \fIkey\fP に対応するセマフォ集合が存在せず、 \fIsemflg\fP に \fBIPC_CREAT\fP が指定されてもいない。
116 .TP 
117 \fBENOMEM\fP
118 セマフォ集合を作成しようとしたが、新しいデータ構造体を 作成するのに十分なメモリがシステムに存在しない。
119 .TP 
120 \fBENOSPC\fP
121 セマフォ集合を作成しようとすると、システムのセマフォ集合の 最大数 (\fBSEMMNI\fP)  か、システム全体のセマフォの最大数 (\fBSEMMNS\fP)
122 のいずれかを超えてしまう。
123 .SH 準拠
124 .\" SVr4 documents additional error conditions EFBIG, E2BIG, EAGAIN,
125 .\" ERANGE, EFAULT.
126 SVr4, POSIX.1\-2001.
127 .SH 注意
128 .\" Like Linux, the FreeBSD man pages still document
129 .\" the inclusion of these header files.
130 The inclusion of \fI<sys/types.h>\fP and \fI<sys/ipc.h>\fP isn't
131 required on Linux or by any version of POSIX.  However, some old
132 implementations required the inclusion of these header files, and the SVID
133 also documented their inclusion.  Applications intended to be portable to
134 such old systems may need to include these header files.
135
136 \fBIPC_PRIVATE\fP はフラグ・フィールドに指定するものではなく、 \fIkey_t\fP 型である。 この特別な値が \fIkey\fP に指定されると、
137 \fBsemget\fP()  \fIsemflg\fP の下位 9 ビット以外は全て無視し、 (成功した場合は) 新しいセマフォ集合を作成する。
138 .PP
139 セマフォ集合のリソースに関する制限のうち、 \fBsemget\fP()  に影響を及ぼすものを以下に挙げる:
140 .TP 
141 \fBSEMMNI\fP
142 .\" This /proc file is not available in Linux 2.2 and earlier -- MTK
143 システム全体のセマフォ集合の最大数: 方針依存 (Linux では、この制限値は \fI/proc/sys/kernel/sem\fP
144 の第4フィールドに対応し、読み出しも変更もできる)。
145 .TP 
146 \fBSEMMSL\fP
147 semid あたりのセマフォの最大数: 実装依存 (Linux では、この制限値は \fI/proc/sys/kernel/sem\fP
148 の第1フィールドに対応し、読み出しも変更もできる)。
149 .TP 
150 \fBSEMMNS\fP
151 システム全体のセマフォの最大数: 方針依存 (Linux では、この制限値は \fI/proc/sys/kernel/sem\fP
152 の第2フィールドに対応し、読み出しも変更もできる)。 \fBSEMMSL * SEMMNI\fP より大きな値は意味を持たない。
153 .SH バグ
154 \fBIPC_PRIVATE\fP という名前を選んだのはおそらく失敗であろう。 \fBIPC_NEW\fP の方がより明確にその機能を表しているだろう。
155 .LP
156 .\" In fact they are initialized to zero on Linux, but POSIX.1-2001
157 .\" does not specify this, and we can't portably rely on it.
158 セマフォ集合内のセマフォは \fBsemget\fP()  では初期化されない。 このセマフォを初期化するには、セマフォ集合に対して \fBsemctl\fP(2)
159 を使って \fBSETVAL\fP か \fBSETALL\fP 操作を実行する必要がある。 (複数箇所からセマフォ集合の操作が行われる場面では、
160 誰が最初に集合を初期化すればよいか分からない。 この状況を避けるには、 \fBsemctl\fP(2)  の \fBIPC_STAT\fP
161 操作で取得できるセマフォのデータ構造体の \fIsem_otime\fP が 0 以外になっているかをチェックすればよい。)
162 .SH 関連項目
163 \fBsemctl\fP(2), \fBsemop\fP(2), \fBftok\fP(3), \fBcapabilities\fP(7),
164 \fBsem_overview\fP(7), \fBsvipc\fP(7)
165 .SH この文書について
166 この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.50 の一部
167 である。プロジェクトの説明とバグ報告に関する情報は
168 http://www.kernel.org/doc/man\-pages/ に書かれている。