OSDN Git Service

(split) [JM:00127] Fix a translation mistake in semop(2).
[linuxjm/LDP_man-pages.git] / draft / man2 / semop.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 1996-10-22, Eric S. Raymond <esr@thyrsus.com>
24 .\" Modified 2002-01-08, Michael Kerrisk <mtk.manpages@gmail.com>
25 .\" Modified 2003-04-28, Ernie Petrides <petrides@redhat.com>
26 .\" Modified 2004-05-27, Michael Kerrisk <mtk.manpages@gmail.com>
27 .\" Modified, 11 Nov 2004, Michael Kerrisk <mtk.manpages@gmail.com>
28 .\"     Language and formatting clean-ups
29 .\"     Added notes on /proc files
30 .\" 2005-04-08, mtk, Noted kernel version numbers for semtimedop()
31 .\" 2007-07-09, mtk, Added an EXAMPLE code segment.
32 .\"
33 .\" Japanese Version Copyright (c) 1997 HANATAKA Shinya
34 .\"         all rights reserved.
35 .\" Translated 1997-02-23, HANATAKA Shinya <hanataka@abyss.rim.or.jp>
36 .\" Updated 2003-02-09, Kentaro Shirakata <argrath@ub32.org>
37 .\" Updated 2003-09-12, Kentaro Shirakata <argrath@ub32.org>
38 .\" Updated 2005-03-01, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
39 .\" Updated 2005-04-17, Akihiro MOTOKI
40 .\" Updated 2005-09-06, Akihiro MOTOKI
41 .\" Updated 2007-05-01, Akihiro MOTOKI, LDP v2.46
42 .\"
43 .\"WORD:        semaphore               ¥»¥Þ¥Õ¥©
44 .\"WORD:        member                  ¥á¥ó¥Ð¡¼
45 .\"WORD:        process                 ¥×¥í¥»¥¹
46 .\"WORD:        system call             ¥·¥¹¥Æ¥à¥³¡¼¥ë
47 .\"WORD:        undo                    ¥¢¥ó¥É¥¥
48 .\"WORD:        signal                  ¥·¥°¥Ê¥ë
49 .\"WORD:        catch                   Êá³Í(catch)
50 .\"WORD:        process-ID              ¥×¥í¥»¥¹ID
51 .\"WORD:        policy                  Êý¿Ë
52 .\"WORD:        implement               ¼ÂÁõ
53 .\"WORD:        queue                   ¥­¥å¡¼
54 .\"WORD:        free                    ²òÊü(free).
55 .\"WORD:        memory                  ¥á¥â¥ê
56 .\"WORD:        anonymous structure     ÌµÌ¾¹½Â¤ÂÎ
57 .\"WORD:        time limit              À©¸Â»þ´Ö
58 \"
59 .TH SEMOP 2 2008-10-04 "Linux" "Linux Programmer's Manual"
60 .\"O .SH NAME
61 .SH Ì¾Á°
62 .\"O semop, semtimedop \- semaphore operations
63 semop, semtimedop \- ¥»¥Þ¥Õ¥©¤ÎÁàºî
64 .\"O .SH SYNOPSIS
65 .SH ½ñ¼°
66 .nf
67 .B #include <sys/types.h>
68 .B #include <sys/ipc.h>
69 .B #include <sys/sem.h>
70 .sp
71 .BI "int semop(int " semid ", struct sembuf *" sops ", unsigned " nsops );
72 .sp
73 .BI "int semtimedop(int " semid ", struct sembuf *" sops ", unsigned " nsops ,
74 .BI "               struct timespec *" timeout );
75 .fi
76 .sp
77 .in -4n
78 .\"O Feature Test Macro Requirements for glibc (see
79 .\"O .BR feature_test_macros (7)):
80 glibc ¸þ¤±¤Îµ¡Ç½¸¡ºº¥Þ¥¯¥í¤ÎÍ×·ï
81 .RB ( feature_test_macros (7)
82 »²¾È):
83 .in
84 .sp
85 .BR semtimedop ():
86 _GNU_SOURCE
87 .\"O .SH DESCRIPTION
88 .SH ÀâÌÀ
89 .\"O Each semaphore in a semaphore set has the following associated values:
90 ¥»¥Þ¥Õ¥©½¸¹ç (semaphore set) ¤Î¥á¥ó¥Ð¡¼¤Î³Æ¥»¥Þ¥Õ¥©¤Ï
91 °Ê²¼¤Î´ØÏ¢¾ðÊó¤ò»ý¤Ã¤Æ¤¤¤ë:
92 .sp
93 .in +4n
94 .nf
95 .\"O unsigned short  semval;   /* semaphore value */
96 .\"O unsigned short  semzcnt;  /* # waiting for zero */
97 .\"O unsigned short  semncnt;  /* # waiting for increase */
98 .\"O pid_t           sempid;   /* process that did last op */
99 unsigned short  semval;   /* ¥»¥Þ¥Õ¥©ÃÍ */
100 unsigned short  semzcnt;  /* ¥¼¥í¤òÂÔ¤Ä¥×¥í¥»¥¹¿ô */
101 unsigned short  semncnt;  /* Áý²Ã¤òÂÔ¤Ä¥×¥í¥»¥¹¿ô */
102 pid_t           sempid;   /* ºÇ¸å¤ËÁàºî¤ò¹Ô¤Ê¤Ã¤¿¥×¥í¥»¥¹ */
103 .sp
104 .in -4n
105 .fi
106 .\"O .BR semop ()
107 .\"O performs operations on selected semaphores in the set indicated by
108 .\"O .IR semid .
109 .BR semop ()
110 ¤Ï
111 .I semid
112 ¤Ç»ØÄꤵ¤ì¤¿¥»¥Þ¥Õ¥©½¸¹ç¤ÎÁªÂò¤µ¤ì¤¿¥»¥Þ¥Õ¥©¤ËÂФ·¤ÆÁàºî¤ò¹Ô¤¦¡£
113 .\"O Each of the
114 .\"O .I nsops
115 .\"O elements in the array pointed to by
116 .\"O .I sops
117 .\"O specifies an operation to be performed on a single semaphore.
118 .\"O The elements of this structure are of type
119 .\"O .IR "struct sembuf" ,
120 .\"O containing the following members:
121 .I sops
122 ¤Ï
123 .I nsops
124 ¸Ä¤ÎÍ×ÁǤÎÇÛÎó¤ò»Ø¤·¡¢ÇÛÎó¤Î³ÆÍ×ÁǤϸġ¹¤Î¥»¥Þ¥Õ¥©¤Ë
125 ÂФ¹¤ëÁàºî¤ò¼¨¤¹¡£¤½¤Î·¿¤Ï
126 .I struct sembuf
127 ¤Ç¡¢¼¡¤Î¥á¥ó¥Ð¤ò»ý¤Ä:
128 .sp
129 .in +4n
130 .nf
131 .\"O unsigned short sem_num;  /* semaphore number */
132 .\"O short          sem_op;   /* semaphore operation */
133 .\"O short          sem_flg;  /* operation flags */
134 unsigned short sem_num;  /* ¥»¥Þ¥Õ¥©ÈÖ¹æ */
135 short          sem_op;   /* ¥»¥Þ¥Õ¥©Áàºî */
136 short          sem_flg;  /* Áàºî¥Õ¥é¥° */
137 .sp
138 .in -4n
139 .fi
140 .\"O Flags recognized in
141 .\"O .I sem_flg
142 .\"O are
143 .\"O .B IPC_NOWAIT
144 .\"O and
145 .\"O .BR SEM_UNDO .
146 .\"O If an operation specifies
147 .\"O .BR SEM_UNDO ,
148 .\"O it will be automatically undone when the process terminates.
149 .I sem_flg
150 ¤Ë¤Ï
151 .B IPC_NOWAIT
152 ¤È
153 .B SEM_UNDO
154 ¤¬ÀßÄê¤Ç¤­¤ë¡£
155 .B SEM_UNDO
156 ¤¬»ØÄꤵ¤ì¤¿Áàºî¤Ï¡¢¤½¤Î¥×¥í¥»¥¹¤¬½ªÎ»¤·¤¿»þ¤Ë¼«Æ°Åª¤Ë¼è¤ê¾Ã¤µ¤ì¤ë¡£
157 .PP
158 .\"O The set of operations contained in
159 .\"O .I sops
160 .\"O is performed in
161 .\"O .IR "array order" ,
162 .\"O and
163 .\"O .IR atomically ,
164 .\"O that is, the operations are performed either as a complete unit,
165 .\"O or not at all.
166 .I sops
167 ¤Ë´Þ¤Þ¤ì¤ëÁàºî¤Î½¸¹ç¤Ï¡¢
168 .I "ÇÛÎó¤Î½ç½ø"
169 ¤Ç¡¢
170 .I ¥¢¥È¥ß¥Ã¥¯¤Ë
171 ¼Â¹Ô¤µ¤ì¤ë¡£
172 ¤¹¤Ê¤ï¤Á¡¢Á´¤Æ¤ÎÁàºî¤¬´°Á´¤Ë¼Â¹Ô¤µ¤ì¤ë¤«¡¢Á´¤¯¼Â¹Ô¤µ¤ì¤Ê¤¤¤«¤Î
173 ¤É¤Á¤é¤«¤È¤Ê¤ë¡£
174
175 .\"O The behavior of the system call if not all operations can be
176 .\"O performed immediately depends on the presence of the
177 .\"O .B IPC_NOWAIT
178 .\"O flag in the individual
179 .\"O .I sem_flg
180 .\"O fields, as noted below.
181 Á´¤Æ¤ÎÁàºî¤¬Ä¾¤Á¤Ë¼Â¹Ô¤Ç¤­¤Ê¤¤¾ì¹ç¤Î¤³¤Î¥·¥¹¥Æ¥à¥³¡¼¥ë¤Î¿¶¤ëÉñ¤¤¤Ï
182 ¸Ä¡¹¤ÎÁàºî¤Î
183 .I sem_flg
184 ¥Õ¥£¡¼¥ë¥É¤Ë
185 .B IPC_NOWAIT
186 ¤¬Â¸ºß¤¹¤ë¤«¤Ë¤è¤Ã¤Æ·è¤Þ¤ê¡¢¸å½Ò¤Î¤è¤¦¤Ë¤Ê¤ë¡£
187
188 .\"O Each operation is performed on the
189 .\"O .IR sem_num \-th
190 .\"O semaphore of the semaphore set, where the first semaphore of the set
191 .\"O is numbered 0.
192 ¤½¤ì¤¾¤ì¤ÎÁàºî¤Ï¥»¥Þ¥Õ¥©½¸¹ç¤Î
193 .IR sem_num ÈÖÌÜ
194 ¤Î¥»¥Þ¥Õ¥©¤ËÂФ·¤Æ¼Â¹Ô¤µ¤ì¤ë¡£¥»¥Þ¥Õ¥©½¸¹ç¤ÎºÇ½é¤Î¥»¥Þ¥Õ¥©¤Ë¤Ï
195 ÈÖ¹æ 0 ¤¬¿¶¤é¤ì¤ë¡£
196 .\"O There are three types of operation, distinguished by the value of
197 .\"O .IR sem_op .
198 ¤½¤·¤ÆÁàºî¤Ï»°¼ïÎढ¤ê¡¢
199 .I sem_op
200 ¤ÎÃͤǶèÊ̤µ¤ì¤ë¡£
201 .PP
202 .\"O If
203 .\"O .I sem_op
204 .\"O is a positive integer, the operation adds this value to
205 .\"O the semaphore value
206 .\"O .RI  ( semval ).
207 .\"O Furthermore, if
208 .\"O .B SEM_UNDO
209 .\"O is specified for this operation, the system updates the process undo count
210 .\"O .RI ( semadj )
211 .\"O for this semaphore.
212 .\"O This operation can always proceed \(em it never forces a process to wait.
213 .\"O The calling process must have alter permission on the semaphore set.
214 .I sem_op
215 ¤¬Àµ¤ÎÀ°¿ô¤Î¾ì¹ç¡¢Áàºî¤È¤·¤Æ¤½¤ÎÃͤò¥»¥Þ¥Õ¥©¤ÎÃÍ
216 .RI ( semval )
217 ¤Ë²Ã¤¨¤ë¡£¤µ¤é¤Ë¤³¤ÎÁàºî¤Ë
218 .B SEM_UNDO
219 ¤¬»ØÄꤵ¤ì¤Æ¤¤¤ë¾ì¹ç¤Ï¡¢¥·¥¹¥Æ¥à¤Ï¤³¤Î¥»¥Þ¥Õ¥©¤Î ¥×¥í¥»¥¹¡¦¥¢¥ó¥É¥¥¿ô
220 .RI ( semadj )
221 ¤ò¹¹¿·¤¹¤ë¡£
222 ¤³¤ÎÁàºî¤Ïɬ¤º¼Â¹Ô¤Ç¤­¡¢¥×¥í¥»¥¹¤ÎÄä»ß¤Ïµ¯¤³¤é¤Ê¤¤¡£
223 ¸Æ¤Ó½Ð¤·¸µ¥×¥í¥»¥¹¤ÏÂоݤΥ»¥Þ¥Õ¥©½¸¹ç¤òÊѹ¹¤¹¤ëµö²Ä¤¬¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£
224 .PP
225 .\"O If
226 .\"O .I sem_op
227 .\"O is zero, the process must have read permission on the semaphore
228 .\"O set.
229 .\"O This is a "wait-for-zero" operation: if
230 .\"O .I semval
231 .\"O is zero, the operation can immediately proceed.
232 .I sem_op
233 ¤¬ 0 ¤Î¾ì¹ç¡¢¡Ö¥¼¥í¤Þ¤ÇÂԤġ×Áàºî¤Ç¤¢¤ë¡£¤³¤Î¾ì¹ç¡¢¥×¥í¥»¥¹¤Ï
234 ¤½¤Î¥»¥Þ¥Õ¥©½¸¹ç¤ËÂФ¹¤ëÆɤ߹þ¤ßµö²Ä¤¬¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£
235 .I semval
236 ¤¬ 0 ¤Ê¤é¤Ð¡¢Áàºî¤Ïľ¤Á¤Ë¹Ô¤ï¤ì¤ë¡£
237 .\"O Otherwise, if
238 .\"O .B IPC_NOWAIT
239 .\"O is specified in
240 .\"O .IR sem_flg ,
241 .\"O .BR semop ()
242 .\"O fails with
243 .\"O .I errno
244 .\"O set to
245 .\"O .B EAGAIN
246 .\"O (and none of the operations in
247 .\"O .I sops
248 .\"O is performed).
249 .I semval
250 ¤¬ 0 ¤Ç¤Ê¤¤¾ì¹ç¡¢
251 .I sem_flg
252 ¤Ë
253 .B IPC_NOWAIT
254 ¤¬»ØÄꤵ¤ì¤Æ¤¤¤ì¤Ð¡¢
255 .BR semop ()
256 ¤Ï¼ºÇÔ¤·¡¢
257 .B errno
258 ¤Ë
259 .B EAGAIN
260 ¤¬ÀßÄꤵ¤ì¤ë (¤³¤Î¤È¤­
261 .I sops
262 ¤ËÂФ¹¤ëÁàºî¤ÏÁ´¤¯¼Â¹Ô¤µ¤ì¤Ê¤¤)¡£
263 .\"O Otherwise
264 .\"O .I semzcnt
265 .\"O (the count of processes waiting until this semaphore's value becomes zero)
266 .\"O is incremented by one and the process sleeps until
267 .\"O one of the following occurs:
268 .I sem_flg
269 ¤Ë
270 .B IPC_NOWAIT
271 ¤¬»ØÄꤵ¤ì¤Æ¤¤¤Ê¤¤¾ì¹ç¡¢
272 .I semzcnt
273 (¥»¥Þ¥Õ¥©Ãͤ¬ 0 ¤Ë¤Ê¤ë¤Î¤òÂԤäƤ¤¤ë¥×¥í¥»¥¹¤Î¿ô) ¤ò 1 Áý²Ã¤µ¤»¤Æ¡¢
274 °Ê²¼¤Î¤¤¤º¤ì¤«¤¬µ¯¤³¤ë¤Þ¤Ç¥×¥í¥»¥¹¤òÄä»ß (sleep) ¤¹¤ë¡£
275 .IP \(bu 3
276 .\"O .I semval
277 .\"O becomes 0, at which time the value of
278 .\"O .I semzcnt
279 .\"O is decremented.
280 .I semval
281 ¤¬ 0 ¤Ë¤Ê¤Ã¤¿: ¤³¤Î¤È¤­
282 .I semzcnt
283 ¤ÎÃͤϠ1 ¸º»»¤µ¤ì¤ë¡£
284 .IP \(bu
285 .\"O The semaphore set
286 .\"O is removed:
287 .\"O .BR semop ()
288 .\"O fails, with
289 .\"O .I errno
290 .\"O set to
291 .\"O .BR EIDRM .
292 ¥»¥Þ¥Õ¥©½¸¹ç¤¬ºï½ü¤µ¤ì¤¿: ¤³¤Î¤È¤­
293 .BR semop ()
294 ¤Ï¼ºÇÔ¤·¡¢
295 .I errno
296 ¤Ë
297 .B EIDRM
298 ¤¬ÀßÄꤵ¤ì¤ë¡£
299 .IP \(bu
300 .\"O The calling process catches a signal:
301 .\"O the value of
302 .\"O .I semzcnt
303 .\"O is decremented and
304 .\"O .BR semop ()
305 .\"O fails, with
306 .\"O .I errno
307 .\"O set to
308 .\"O .BR EINTR .
309 ¸Æ¤Ó½Ð¤·¸µ¥×¥í¥»¥¹¤¬¥·¥°¥Ê¥ë¤òÊá³Í¤·¤¿: ¤³¤Î¤È¤­
310 .I semzcnt
311 ¤ÎÃͤϠ1 ¸º»»¤µ¤ì¡¢
312 .BR semop ()
313 ¤Ï¼ºÇÔ¤·
314 .I errno
315 ¤Ë
316 .B EINTR
317 ¤¬ÀßÄꤵ¤ì¤ë¡£
318 .IP \(bu
319 .\"O The time limit specified by
320 .\"O .I timeout
321 .\"O in a
322 .\"O .BR semtimedop ()
323 .\"O call expires:
324 .\"O .BR semop ()
325 .\"O fails, with
326 .\"O .I errno
327 .\"O set to
328 .\"O .BR EAGAIN .
329 .\" motoki: semop () ¤Ï semtimedop () ¤Î´Ö°ã¤¤¡©
330 .BR semtimedop ()
331 ¤Î
332 .I timeout
333 ¤Ç»ØÄꤵ¤ì¤¿À©¸Â»þ´Ö¤¬·Ð²á¤·¤¿: ¤³¤Î¤È¤­
334 .BR semtimedop ()
335 ¤Ï¼ºÇÔ¤·¡¢
336 .I errno
337 ¤Ë
338 .B EAGAIN
339 ¤¬ÀßÄꤵ¤ì¤ë¡£
340 .PP
341 .\"O If
342 .\"O .I sem_op
343 .\"O is less than zero, the process must have alter permission on the
344 .\"O semaphore set.
345 .\"O If
346 .\"O .I semval
347 .\"O is greater than or equal to the absolute value of
348 .\"O .IR sem_op ,
349 .\"O the operation can proceed immediately:
350 .\"O the absolute value of
351 .\"O .I sem_op
352 .\"O is subtracted from
353 .\"O .IR semval ,
354 .\"O and, if
355 .\"O .B SEM_UNDO
356 .\"O is specified for this operation, the system updates the process undo count
357 .\"O .RI ( semadj )
358 .\"O for this semaphore.
359 .I sem_op
360 ¤¬ 0 Ì¤Ëþ¤Î¾ì¹ç¡¢¥×¥í¥»¥¹¤Ë¤Ï¤½¤Î¥»¥Þ¥Õ¥©½¸¹ç¤òÊѹ¹¤¹¤ëµö²Ä¤¬¤Ê¤±¤ì¤Ð
361 ¤Ê¤é¤Ê¤¤¡£
362 .I semval
363 ¤¬
364 .I sem_op
365 ¤ÎÀäÂÐÃͰʾå¤Î¾ì¹ç¤Ï¡¢Áàºî¤Ïľ¤Á¤Ë¼Â¹Ô¤µ¤ì¤ë:
366 .I semval
367 ¤«¤é
368 .I sem_op
369 ¤ÎÀäÂÐÃͤ¬¸º»»¤µ¤ì¤ë¡£
370 ¤µ¤é¤Ë¡¢¤³¤ÎÁàºî¤Ë
371 .B SEM_UNDO
372 ¤¬»ØÄꤵ¤ì¤Æ¤¤¤ë¾ì¹ç¤Ï¡¢¤³¤Î¥»¥Þ¥Õ¥©¤Î¥×¥í¥»¥¹¡¦¥¢¥ó¥É¥¥¿ô
373 .RI ( semadj )
374 ¤ò¹¹¿·¤¹¤ë¡£
375 .\"O If the absolute value of
376 .\"O .I sem_op
377 .\"O is greater than
378 .\"O .IR semval ,
379 .\"O and
380 .\"O .B IPC_NOWAIT
381 .\"O is specified in
382 .\"O .IR sem_flg ,
383 .\"O .BR semop ()
384 .\"O fails, with
385 .\"O .I errno
386 .\"O set to
387 .\"O .B EAGAIN
388 .\"O (and none of the operations in
389 .\"O .I sops
390 .\"O is performed).
391 .I semval
392 ¤¬
393 .I sem_op
394 ¤ÎÀäÂÐÃͤè¤ê¾®¤µ¤¯¡¢
395 .I sem_flg
396 ¤Ë
397 .B IPC_NOWAIT
398 ¤¬»ØÄꤵ¤ì¤¿¾ì¹ç¤Ï¡¢
399 .BR semop ()
400 ¤Ï¼ºÇÔ¤·¡¢
401 .I errno
402 ¤Ë
403 .B EAGAIN
404 ¤¬ÀßÄꤵ¤ì¤ë (¤³¤Î¤È¤­
405 .I sops
406 ¤ÎÁàºî¤ÏÁ´¤¯¼Â¹Ô¤µ¤ì¤Ê¤¤)¡£
407 .\"O Otherwise
408 .\"O .I semncnt
409 .\"O (the counter of processes waiting for this semaphore's value to increase)
410 .\"O is incremented by one and the process sleeps until
411 .\"O one of the following occurs:
412 .B IPC_WAIT
413 ¤¬»ØÄꤵ¤ì¤Æ¤¤¤Ê¤±¤ì¤Ð¡¢
414 .I semncnt
415 (¤³¤Î¥»¥Þ¥Õ¥©¤ÎÃͤ¬Áý²Ã¤¹¤ë¤Î¤òÂԤäƤ¤¤ë¥×¥í¥»¥¹¿ô¤Î¥«¥¦¥ó¥¿)
416 ¤ò 1 Áý²Ã¤µ¤»¤Æ¡¢°Ê²¼¤Î¤¤¤º¤ì¤«¤¬µ¯¤³¤ë¤Þ¤Ç¥×¥í¥»¥¹¤òÄä»ß (sleep) ¤¹¤ë¡£
417 .IP \(bu 3
418 .\"O .I semval
419 .\"O becomes greater than or equal to the absolute value of
420 .\"O .IR sem_op ,
421 .\"O at which time the value of
422 .\"O .I semncnt
423 .\"O is decremented, the absolute value of
424 .\"O .I sem_op
425 .\"O is subtracted from
426 .\"O .I semval
427 .\"O and, if
428 .\"O .B SEM_UNDO
429 .\"O is specified for this operation, the system updates the process undo count
430 .\"O .RI ( semadj )
431 .\"O for this semaphore.
432 .I semval
433 ¤¬
434 .I sem_op
435 ¤ÎÀäÂÐÃͰʾå¤Ë¤Ê¤Ã¤¿: ¤³¤Î¤È¤­
436 .I semncnt
437 ¤¬ 1 ¸º»»¤µ¤ì¡¢
438 .I semval
439 ¤«¤é
440 .I sem_op
441 ¤ÎÀäÂÐÃͤ¬°ú¤«¤ì¤ë¡£
442 ¤³¤ÎÁàºî¤Ë
443 .B SEM_UNDO
444 ¤¬»ØÄꤵ¤ì¤Æ¤¤¤¿¾ì¹ç¤Ë¤Ï¤³¤Î¥»¥Þ¥Õ¥©¤Î¥×¥í¥»¥¹¡¦¥¢¥ó¥É¥¥¿ô
445 .RI ( semadj )
446 ¤â¹¹¿·¤¹¤ë¡£
447 .IP \(bu
448 .\"O The semaphore set is removed from the system:
449 .\"O .BR semop ()
450 .\"O fails, with
451 .\"O .I errno
452 .\"O set to
453 .\"O .BR EIDRM .
454 ¥»¥Þ¥Õ¥©½¸¹ç¤¬¥·¥¹¥Æ¥à¤«¤éºï½ü¤µ¤ì¤¿: ¤³¤Î¤È¤­
455 .BR semop ()
456 ¤Ï¼ºÇÔ¤·
457 .I errno
458 ¤Ë
459 .B EIDRM
460 ¤¬ÀßÄꤵ¤ì¤ë¡£
461 .IP \(bu
462 .\"O The calling process catches a signal:
463 .\"O the value of
464 .\"O .I semncnt
465 .\"O is decremented and
466 .\"O .BR semop ()
467 .\"O fails, with
468 .\"O .I errno
469 .\"O set to
470 .\"O .BR EINTR .
471 ¸Æ¤Ó½Ð¤·¤¿¥×¥í¥»¥¹¤¬¥·¥°¥Ê¥ë¤òÊá³Í¤·¤¿: ¤³¤Î¤È¤­
472 .I semncnt
473 ¤¬ 1 ¸º»»¤µ¤ì¡¢
474 .BR semop ()
475 ¤Ï¼ºÇÔ¤·
476 .I errno
477 ¤Ë
478 .B EINTR
479 ¤¬ÀßÄꤵ¤ì¤ë¡£
480 .IP \(bu
481 .\"O The time limit specified by
482 .\"O .I timeout
483 .\"O in a
484 .\"O .BR semtimedop ()
485 .\"O call expires: the system call fails, with
486 .\"O .I errno
487 .\"O set to
488 .\"O .BR EAGAIN .
489 .\" motoki: the system call ¤Ï semtimedop () ¤Î¤³¤È¡©
490 .BR semtimedop ()
491 ¤Î
492 .I timeout
493 ¤Ç»ØÄꤵ¤ì¤¿À©¸Â»þ´Ö¤¬·Ð²á¤·¤¿: ¤³¤Î¤È¤­
494 .BR semtimedop ()
495 ¤Ï¼ºÇÔ¤·¡¢
496 .I errno
497 ¤Ë
498 .B EAGAIN
499 ¤¬ÀßÄꤵ¤ì¤ë¡£
500 .PP
501 .\"O On successful completion, the
502 .\"O .I sempid
503 .\"O value for each semaphore specified in the array pointed to by
504 .\"O .I sops
505 .\"O is set to the process ID of the calling process.
506 Áàºî¤¬À®¸ù¤·¤¿¾ì¹ç¡¢
507 .I sops
508 ¤¬»Ø¤¹ÇÛÎó¤Ë¤è¤Ã¤ÆÁàºîÂоݤȤʤ俳ƥ»¥Þ¥Õ¥©¤Î
509 .I sempid
510 ¥á¥ó¥Ð¡¼¤Ë¤Ï¸Æ¤Ó½Ð¤·¤¿¥×¥í¥»¥¹¤Î¥×¥í¥»¥¹ ID ¤¬ÀßÄꤵ¤ì¤ë¡£
511 .\"O In addition, the
512 .\"O .I sem_otime
513 .\"O .\" and
514 .\"O .\" .I sem_ctime
515 .\"O is set to the current time.
516 ¤µ¤é¤Ë
517 .I sem_otime
518 .\" ¤È
519 .\" .I sem_ctime
520 ¤Ë¸½ºß»þ¹ï¤¬ÀßÄꤵ¤ì¤ë¡£
521 .PP
522 .\"O The function
523 .\"O .BR semtimedop ()
524 .\"O behaves identically to
525 .\"O .BR semop ()
526 .\"O except that in those cases were the calling process would sleep,
527 .\"O the duration of that sleep is limited by the amount of elapsed
528 .\"O time specified by the
529 .\"O .I timespec
530 .\"O structure whose address is passed in the
531 .\"O .I timeout
532 .\"O argument.
533 .BR semtimedop ()
534 ´Ø¿ô¤Î¿¶¤ëÉñ¤¤¤Ï
535 .BR semop ()
536 ¤ÈÁ´¤¯Æ±¤¸¤À¤¬¡¢
537 ¸Æ¤Ó½Ð¤·¸µ¥×¥í¥»¥¹¤¬Ää»ß¤¹¤ë¾ì¹ç¡¢Ää»ß´ü´Ö¤Î¾å¸Â¤¬
538 .I timeout
539 °ú¤­¿ô¤Î»Ø¤¹
540 .I timespec
541 ¹½Â¤ÂΤǻØÄꤵ¤ì¤¿»þ´Ö¤È¤Ê¤ëÅÀ¤À¤±¤¬°Û¤Ê¤ë¡£
542 .\"O If the specified time limit has been reached,
543 .\"O .BR semtimedop ()
544 .\"O fails with
545 .\"O .I errno
546 .\"O set to
547 .\"O .B EAGAIN
548 .\"O (and none of the operations in
549 .\"O .I sops
550 .\"O is performed).
551 »ØÄꤷ¤¿À©¸Â»þ´Ö¤Ë㤷¤¿¾ì¹ç¤Ï¡¢
552 .BR semtimedop ()
553 ¤Ï¼ºÇÔ¤·¡¢
554 .I errno
555 ¤Ë
556 .B EAGAIN
557 ¤¬ÀßÄꤵ¤ì¤ë
558 (¤³¤Î¤È¤­
559 .I sops
560 ¤ÎÁàºî¤Ï¼Â¹Ô¤µ¤ì¤Ê¤¤)¡£
561 .\"O If the
562 .\"O .I timeout
563 .\"O argument is NULL,
564 .\"O then
565 .\"O .BR semtimedop ()
566 .\"O behaves exactly like
567 .\"O .BR semop ().
568 .I timeout
569 °ú¤­¿ô¤¬ NULL ¤Î¾ì¹ç¡¢
570 .BR semtimedop ()
571 ´Ø¿ô¤Î¿¶¤ëÉñ¤¤¤Ï
572 .BR semop ()
573 ´Ø¿ô¤ÈÁ´¤¯Æ±¤¸¤Ë¤Ê¤ë¡£
574 .\"O .SH "RETURN VALUE"
575 .SH ÊÖ¤êÃÍ
576 .\"O If successful
577 .\"O .BR semop ()
578 .\"O and
579 .\"O .BR semtimedop ()
580 .\"O return 0;
581 .\"O otherwise they return \-1
582 .\"O with
583 .\"O .I errno
584 .\"O indicating the error.
585 À®¸ù¤·¤¿¾ì¹ç¡¢
586 .BR semop ()
587 ¤È
588 .BR semtimedop ()
589 ¤Ï 0 ¤òÊÖ¤¹¡£¤½¤¦¤Ç¤Ê¤±¤ì¤Ð \-1 ¤òÊÖ¤·¡¢
590 ¥¨¥é¡¼¤ò¼¨¤¹
591 .I errno
592 ¤òÀßÄꤹ¤ë¡£
593 .\"O .SH ERRORS
594 .SH ¥¨¥é¡¼
595 .\"O On failure,
596 .\"O .I errno
597 .\"O is set to one of the following:
598 ¼ºÇÔ¤·¤¿¾ì¹ç¡¢
599 .I errno
600 ¤Ë°Ê²¼¤Î¤É¤ì¤«¤¬ÀßÄꤵ¤ì¤ë:
601 .TP
602 .B E2BIG
603 .\"O The argument
604 .\"O .I nsops
605 .\"O is greater than
606 .\"O .BR SEMOPM ,
607 .\"O the maximum number of operations allowed per system
608 .\"O call.
609 .I nsops
610 °ú¤­¿ô¤¬
611 .B SEMOPM
612 ¤è¤êÂ礭¤¤¡£
613 .B SEMOPM
614 ¤Ï°ì²ó¤Î¥·¥¹¥Æ¥à¥³¡¼¥ë¤Çµö¤µ¤ì¤ëÁàºî¤ÎºÇÂç¸Ä¿ô¤Ç¤¢¤ë¡£
615 .TP
616 .B EACCES
617 .\"O The calling process does not have the permissions required
618 .\"O to perform the specified semaphore operations,
619 .\"O and does not have the
620 .\"O .B CAP_IPC_OWNER
621 .\"O capability.
622 ¸Æ¤Ó½Ð¤·¸µ¥×¥í¥»¥¹¤Ë¤Ï»ØÄꤵ¤ì¤¿¥»¥Þ¥Õ¥©Áàºî¤ò¹Ô¤¦¤Î¤Ë
623 ɬÍפʥ¢¥¯¥»¥¹µö²Ä¤¬¤Ê¤¯¡¢
624 .B CAP_IPC_OWNER
625 ¥±¡¼¥Ñ¥Ó¥ê¥Æ¥£¤â¤Ê¤¤¡£
626 .TP
627 .B EAGAIN
628 .\"O An operation could not proceed immediately and either
629 .\"O .B IPC_NOWAIT
630 .\"O was specified in
631 .\"O .I sem_flg
632 .\"O or the time limit specified in
633 .\"O .I timeout
634 .\"O expired.
635 Áàºî¤òľ¤Á¤Ë½èÍý¤¹¤ë¤³¤È¤¬¤Ç¤­¤º¡¢¤«¤Ä
636 .I sem_flg
637 ¤Ë
638 .B IPC_NOWAIT
639 ¤¬»ØÄꤵ¤ì¤Æ¤¤¤ë¤«
640 .I timeout
641 ¤Ç»ØÄꤵ¤ì¤¿À©¸Â»þ´Ö¤¬·Ð²á¤·¤¿¡£
642 .TP
643 .B EFAULT
644 .\"O An address specified in either the
645 .\"O .I sops
646 .\"O or the
647 .\"O .I timeout
648 .\"O arguments isn't accessible.
649 °ú¤­¿ô
650 .I sops
651 ¤«
652 .I timeout
653 ¤¬»Ø¤·¤Æ¤¤¤ë¥¢¥É¥ì¥¹¤Ë¥¢¥¯¥»¥¹¤Ç¤­¤Ê¤¤¡£
654 .TP
655 .B EFBIG
656 .\"O For some operation the value of
657 .\"O .I sem_num
658 .\"O is less than 0 or greater than or equal to the number
659 .\"O of semaphores in the set.
660 ¤¢¤ëÁàºî¤Ç¡¢
661 .I sem_num
662 ¤ÎÃͤ¬ 0 Ì¤Ëþ¤«¡¢½¸¹çÆâ¤Î¥»¥Þ¥Õ¥©¤Î¿ô°Ê¾å¤Ç¤¢¤ë¡£
663 .TP
664 .B EIDRM
665 .\"O The semaphore set was removed.
666 ¥»¥Þ¥Õ¥©½¸¹ç¤¬ºï½ü¤µ¤ì¤¿¡£
667 .TP
668 .B EINTR
669 .\"O While blocked in this system call, the process caught a signal; see
670 .\"O .BR signal (7).
671 ¤³¤Î¥·¥¹¥Æ¥à¥³¡¼¥ë¤ÇÄä»ß¤·¤Æ¤¤¤ë»þ¤Ë¥×¥í¥»¥¹¤¬¥·¥°¥Ê¥ë¤òÊá³Í¤·¤¿¡£
672 .BR single (7)
673 »²¾È¡£
674 .TP
675 .B EINVAL
676 .\"O The semaphore set doesn't exist, or
677 .\"O .I semid
678 .\"O is less than zero, or
679 .\"O .I nsops
680 .\"O has a nonpositive value.
681 ¥»¥Þ¥Õ¥©½¸¹ç¤¬Â¸ºß¤·¤Ê¤¤¤«¡¢
682 .I semid
683 ¤¬ 0 Ì¤Ëþ¤Ç¤¢¤ë¤«¡¢
684 .I nsops
685 ¤¬Àµ¤Î¿ô¤Ç¤Ê¤¤¡£
686 .TP
687 .B ENOMEM
688 .\"O The
689 .\"O .I sem_flg
690 .\"O of some operation specified
691 .\"O .B SEM_UNDO
692 .\"O and the system does not have enough memory to allocate the undo
693 .\"O structure.
694 ¤¢¤ëÁàºî¤Ç
695 .I sem_flg
696 ¤Ë
697 .B SEM_UNDO
698 ¤¬»ØÄꤵ¤ì¤¿¤¬¡¢¥·¥¹¥Æ¥à¤Ë¥¢¥ó¥É¥¥¹½Â¤ÂΤ˳ä¤êÅö¤Æ¤ë½½Ê¬¤Ê¥á¥â¥ê¤¬¤Ê¤¤¡£
699 .TP
700 .B ERANGE
701 .\"O For some operation
702 .\"O .I sem_op+semval
703 .\"O is greater than
704 .\"O .BR SEMVMX ,
705 .\"O the implementation dependent maximum value for
706 .\"O .IR semval .
707 ¤¢¤ëÁàºî¤Ç
708 .I sem_op+semval
709 ¤¬
710 .B SEMVMX
711 ¤è¤êÂ礭¤¤¡£
712 .B SEMVMX
713 ¤Ï
714 .I semval
715 ¤ÎºÇÂçÃͤǡ¢¤½¤ÎÃͤϼÂÁõ°Í¸¤Ç¤¢¤ë¡£
716 .\"O .SH VERSIONS
717 .SH ¥Ð¡¼¥¸¥ç¥ó
718 .\"O .BR semtimedop ()
719 .\"O first appeared in Linux 2.5.52,
720 .\"O and was subsequently backported into kernel 2.4.22.
721 .BR semtimedop ()
722 ¤Ï Linux 2.5.52 ¤Ç½é¤á¤ÆÅо줷¡¢
723 ¤½¤ì¤«¤é¥«¡¼¥Í¥ë 2.4.22 ¤Ë¤â°Ü¿¢¤µ¤ì¤¿¡£
724 .\"O Glibc support for
725 .\"O .BR semtimedop ()
726 .\"O first appeared in version 2.3.3.
727 .BR semtimedop ()
728 ¤Î glibc ¤Ç¤Î¥µ¥Ý¡¼¥È¤Ï¥Ð¡¼¥¸¥ç¥ó 2.3.3 ¤Ç½é¤á¤ÆÅо줷¤¿¡£
729 .\"O .SH "CONFORMING TO"
730 .SH ½àµò
731 SVr4, POSIX.1-2001.
732 .\"O .\" SVr4 documents additional error conditions EINVAL, EFBIG, ENOSPC.
733 .\" SVr4 ¤Ë¤Ï¡¢ÄɲäǠEINVAL, EFBIG, ENOSPC ¤Î¥¨¥é¡¼¾õÂ֤ˤĤ¤¤Æ¤Î
734 .\" µ­½Ò¤¬¤¢¤ë¡£
735 .\"O .SH NOTES
736 .SH Ãí°Õ
737 .\"O The
738 .\"O .I sem_undo
739 .\"O structures of a process aren't inherited by the child produced by
740 .\"O .BR fork (2),
741 .\"O but they are inherited across an
742 .\"O .BR execve (2)
743 .\"O system call.
744 ¤¢¤ë¥×¥í¥»¥¹¤Î
745 .I sem_undo
746 ¹½Â¤ÂΤÏ
747 .BR fork (2)
748 ¤ÇÀ¸À®¤µ¤ì¤¿»Ò¥×¥í¥»¥¹¤Ë¤Ï·Ñ¾µ¤µ¤ì¤Ê¤¤¤¬¡¢
749 .BR execve (2)
750 ¥·¥¹¥Æ¥à¥³¡¼¥ë¤Î¾ì¹ç¤Ï·Ñ¾µ¤µ¤ì¤ë¡£
751 .PP
752 .\"O .BR semop ()
753 .\"O is never automatically restarted after being interrupted by a signal handler,
754 .\"O regardless of the setting of the
755 .\"O .B SA_RESTART
756 .\"O flag when establishing a signal handler.
757 .BR semop ()
758 ¤Ï¥·¥°¥Ê¥ë¥Ï¥ó¥É¥é¤Ë¤è¤Ã¤ÆÃæÃǤµ¤ì¤¿¸å¤Ë¡¢
759 ·è¤·¤Æ¼«Æ°Åª¤ËºÆ³«¤¹¤ë¤³¤È¤Ï¤Ê¤¤¡£
760 ¤¿¤È¤¨¥·¥°¥Ê¥ë¥Ï¥ó¥É¥é¤ÎÀßÄê»þ¤Ë
761 .B SA_RESTART
762 ¥Õ¥é¥°¤¬¥»¥Ã¥È¤µ¤ì¤Æ¤¤¤Æ¤âºÆ³«¤¹¤ë¤³¤È¤Ï¤Ê¤¤
763 .PP
764 .\"O .I semadj
765 .\"O is a per-process integer which is simply the (negative) count
766 .\"O of all semaphore operations performed specifying the
767 .\"O .B SEM_UNDO
768 .\"O flag.
769 .I semadj
770 ¤Ï¥×¥í¥»¥¹¤´¤È¤ÎÀ°¿ô¤Ç¡¢
771 .B SEM_UNDO
772 ¥Õ¥é¥°¤òÀßÄꤷ¤Æ¼Â¹Ô¤µ¤ì¤¿Á´¤Æ¤Î¥»¥Þ¥Õ¥©Áàºî¤Î(Éé¿ô¤Î)¥«¥¦¥ó¥¿¤Ç¤¢¤ë¡£
773 .\"O When a semaphore's value is directly set using the
774 .\"O .B SETVAL
775 .\"O or
776 .\"O .B SETALL
777 .\"O request to
778 .\"O .BR semctl (2),
779 .\"O the corresponding
780 .\"O .I semadj
781 .\"O values in all processes are cleared.
782 .BR semctl (2)
783 ¤Ë
784 .B SETVAL
785 ¤Þ¤¿¤Ï
786 .B SETALL
787 ¤ò»ØÄꤷ¡¢¥»¥Þ¥Õ¥©¤ÎÃͤ¬
788 ľÀÜÀßÄꤵ¤ì¤¿¾ì¹ç¤Ë¤Ï¡¢Á´¤Æ¤Î¥×¥í¥»¥¹¤Ë¤ª¤¤¤ÆÂбþ¤¹¤ë
789 .I semadj
790 ¤ÎÃͤ¬¥¯¥ê¥¢¤µ¤ì¤ë¡£
791 .PP
792 .\"O The \fIsemval\fP, \fIsempid\fP, \fIsemzcnt\fP, and \fIsemnct\fP values
793 .\"O for a semaphore can all be retrieved using appropriate
794 .\"O .BR semctl (2)
795 .\"O calls.
796 ¤¢¤ë¥»¥Þ¥Õ¥©¤Î \fIsemval\fP, \fIsempid\fP, \fIsemzcnt\fP, \fIsemnct\fP
797 ¤ÎÃͤϤ¤¤º¤ì¤â¡¢Å¬ÀÚ¤ÊÁàºî¤ò»ØÄꤷ¤Æ
798 .BR semctl (2)
799 ¤ò¸Æ¤Ó½Ð¤¹¤³¤È¤Ç¼èÆÀ¤Ç¤­¤ë¡£
800 .PP
801 .\"O The following limits on semaphore set resources affect the
802 .\"O .BR semop ()
803 .\"O call:
804 ¥»¥Þ¥Õ¥©½¸¹ç¤Î¥ê¥½¡¼¥¹¤Ë´Ø¤¹¤ëÀ©¸Â¤Î¤¦¤Á¡¢
805 .BR semop ()
806 ¤Ë±Æ¶Á¤òµÚ¤Ü¤¹¤â¤Î¤ò°Ê²¼¤Ëµó¤²¤ë:
807 .TP
808 .B SEMOPM
809 .\"O Maximum number of operations allowed for one
810 .\"O .BR semop ()
811 .\"O call (32)
812 .\"O (on Linux, this limit can be read and modified via the third field of
813 .\"O .IR /proc/sys/kernel/sem ).
814 .\"O .\" This /proc file is not available in Linux 2.2 and earlier -- MTK
815 °ì²ó¤Î
816 .BR semop ()
817 ¤Çµö¤µ¤ì¤ëÁàºî¤ÎºÇÂç¿ô (32)¡£
818 (Linux ¤Ç¤Ï¡¢¤³¤ÎÀ©¸ÂÃͤÏ
819 .I /proc/sys/kernel/sem
820 ¤ÎÂè3¥Õ¥£¡¼¥ë¥É¤ËÂбþ¤·¡¢Æɤ߽Ф·¤âÊѹ¹¤â¤Ç¤­¤ë)¡£
821 .\" ¤³¤Î /proc ¥Õ¥¡¥¤¥ë¤Ï Linux 2.2 °ÊÁ°¤Ç¤ÏÍøÍѤǤ­¤Ê¤¤ -- MTK
822 .TP
823 .B SEMVMX
824 .\"O Maximum allowable value for
825 .\"O .IR semval :
826 .\"O implementation dependent (32767).
827 .I semval
828 ¤¬¼è¤êÆÀ¤ëºÇÂçÃÍ: ¼ÂÁõ°Í¸ (32767)¡£
829 .PP
830 .\"O The implementation has no intrinsic limits for
831 .\"O the adjust on exit maximum value
832 .\"O .RB ( SEMAEM ),
833 .\"O the system wide maximum number of undo structures
834 .\"O .RB ( SEMMNU )
835 .\"O and the per-process maximum number of undo entries system parameters.
836 °Ê²¼¤ÎÃͤ˴ؤ·¤Æ¤Ï¼ÂÁõ°Í¸¤ÎÀ©¸Â¤Ï¤Ê¤¤¡£
837 ½ªÎ»»þ¤ÎÄ´À° (adjust on exit) ¤ÎºÇÂçÃÍ
838 .RB ( SEMAEM )¡¢
839 ¥·¥¹¥Æ¥àÁ´ÂΤΥ¢¥ó¥É¥¥¹½Â¤ÂΤκÇÂç¿ô
840 .RB ( SEMMNU )¡¢
841 ¥×¥í¥»¥¹¤¢¤¿¤ê¤Î¥¢¥ó¥É¥¥¹½Â¤ÂΤκÇÂç¿ô¡£
842 .\"O .SH BUGS
843 .SH ¥Ð¥°
844 .\"O When a process terminates, its set of associated
845 .\"O .I semadj
846 .\"O structures is used to undo the effect of all of the
847 .\"O semaphore operations it performed with the
848 .\"O .B SEM_UNDO
849 .\"O flag.
850 ¥×¥í¥»¥¹¤¬½ªÎ»¤¹¤ëºÝ¡¢¥×¥í¥»¥¹¤ËÂбþ¤¹¤ë
851 .I semadj
852 ¤Î½¸¹ç¤ò»È¤Ã¤Æ¡¢
853 .B SEM_UNDO
854 ¥Õ¥é¥°ÉÕ¤­¤Ç¼Â¹Ô¤µ¤ì¤¿Á´¤Æ¤Î¥»¥Þ¥Õ¥©Áàºî¤Î±Æ¶Á¤ò¼è¤ê¾Ã¤¹¡£
855 .\"O This raises a difficulty: if one (or more) of these semaphore adjustments
856 .\"O would result in an attempt to decrease a semaphore's value below zero,
857 .\"O what should an implementation do?
858 ¤³¤ì¤Ë¤è¤ê¤¢¤ëÌäÂ꤬ȯÀ¸¤¹¤ë: ¤³¤ì¤é¤Î¥»¥Þ¥Õ¥©¤ÎÄ´À°¤ò¹Ô¤Ã¤Æ¤¤¤ë¤È¡¢
859 Ãæ¤Ë¤Ï¥»¥Þ¥Õ¥©¤ÎÃͤ¬ 0 Ì¤Ëþ¤ÎÃͤˤ·¤è¤¦¤È¤¹¤ë¾ì¹ç¤¬½Ð¤Æ¤¯¤ë¡£
860 ¤³¤Î¤è¤¦¤Ê¾ì¹ç¡¢¤É¤Î¤è¤¦¤Ë¼ÂÁõ¤¹¤ë¤Ù¤­¤«?
861 .\"O One possible approach would be to block until all the semaphore
862 .\"O adjustments could be performed.
863 .\"O This is however undesirable since it could force process termination to
864 .\"O block for arbitrarily long periods.
865 ¤Ò¤È¤Ä¤Î¹Í¤¨¤é¤ì¤ë¼êË¡¤Ï¡¢Á´¤Æ¤Î¥»¥Þ¥Õ¥©Ä´À°¤¬¼Â¹Ô¤µ¤ì¤ë¤Þ¤Ç
866 Ää»ß¤¹¤ë¤³¤È¤Ç¤¢¤ë¡£¤·¤«¤·¡¢¤³¤ÎÊýË¡¤Ç¤Ï¥×¥í¥»¥¹¤Î½ªÎ»¤¬
867 Ĺ»þ´Ö¤Ë¤ï¤¿¤Ã¤ÆÄä»ß¤µ¤ì¤ë¤³¤È¤¬¤¢¤ë¤Î¤Ç˾¤Þ¤·¤¯¤Ê¤¤¡£
868 ¤·¤«¤â¤É¤ì¤¯¤é¤¤Ä¹»þ´Ö¤Ë¤Ê¤ë¤«¤Ïʬ¤«¤é¤Ê¤¤¡£
869 .\"O Another possibility is that such semaphore adjustments could be ignored
870 .\"O altogether (somewhat analogously to failing when
871 .\"O .B IPC_NOWAIT
872 .\"O is specified for a semaphore operation).
873 Ê̤ÎÁªÂò»è¤È¤·¤Æ¡¢¤³¤Î¤è¤¦¤Ê¥»¥Þ¥Õ¥©Ä´À°¤ò´°Á´¤Ë̵»ë¤·¤Æ¤·¤Þ¤¦ÊýË¡¤¬¤¢¤ë
874 (¤³¤ì¤Ï¥»¥Þ¥Õ¥©Áàºî¤È¤·¤Æ
875 .B IPC_NOWAIT
876 ¤¬»ØÄꤹ¤ë¤Î¤È¾¯¤·»÷¤Æ¤¤¤ë)¡£
877 .\"O Linux adopts a third approach: decreasing the semaphore value
878 .\"O as far as possible (i.e., to zero) and allowing process
879 .\"O termination to proceed immediately.
880 Linux ¤ÏÂè»°¤Î¼êË¡¤òºÎÍѤ·¤Æ¤¤¤ë: ¥»¥Þ¥Õ¥©¤ÎÃͤò½ÐÍè¤ë¤À¤± (¤Ä¤Þ¤ê
881 0 ¤Þ¤Ç) ¸º¾¯¤µ¤»¤Æ¡¢¥×¥í¥»¥¹¤Î½ªÎ»¤òľ¤Á¤Ë³¹Ô¤Ç¤­¤ë¤è¤¦¤Ë¤·¤Æ¤¤¤ë¡£
882
883 .\"O In kernels 2.6.x, x <= 10, there is a bug that in some circumstances
884 .\"O prevents a process that is waiting for a semaphore value to become
885 .\"O zero from being woken up when the value does actually become zero.
886 .\"O This bug is fixed in kernel 2.6.11.
887 .\"O .\" The bug report:
888 .\"O .\" http://marc.theaimsgroup.com/?l=linux-kernel&m=110260821123863&w=2
889 .\"O .\" the fix:
890 .\"O .\" http://marc.theaimsgroup.com/?l=linux-kernel&m=110261701025794&w=2
891 ¥«¡¼¥Í¥ë 2.6.x (x <= 10) ¤Ë¤Ï¡¢¤¢¤ë¾õ¶·¤Ë¤ª¤¤¤Æ¥»¥Þ¥Õ¥©Ãͤ¬ 0 ¤Ë¤Ê¤ë¤Î¤ò
892 ÂԤäƤ¤¤ë¥×¥í¥»¥¹¤¬¡¢¥»¥Þ¥Õ¥©Ãͤ¬¼ÂºÝ¤Ë 0 ¤Ë¤Ê¤Ã¤¿¤È¤­¤Ëµ¯¾² (wake up)
893 ¤µ¤ì¤Ê¤¤¡¢¤È¤¤¤¦¥Ð¥°¤¬¤¢¤ë¡£¤³¤Î¥Ð¥°¤Ï¥«¡¼¥Í¥ë 2.6.11 ¤Ç½¤Àµ¤µ¤ì¤Æ¤¤¤ë¡£
894 .\" ¥Ð¥°¥ì¥Ý¡¼¥È:
895 .\" http://marc.theaimsgroup.com/?l=linux-kernel&m=110260821123863&w=2
896 .\" ½¤Àµ:
897 .\" http://marc.theaimsgroup.com/?l=linux-kernel&m=110261701025794&w=2
898 .\"O .SH EXAMPLE
899 .SH Îã
900 .\"O The following code segment uses
901 .\"O .BR semop ()
902 .\"O to atomically wait for the value of semaphore 0 to become zero,
903 .\"O and then increment the semaphore value by one.
904 °Ê²¼¤ÎÉôʬŪ¤Ê¥³¡¼¥É¤Ï¡¢
905 ¥»¥Þ¥Õ¥© 0 ¤ÎÃͤ¬ 0 ¤Ë¤Ê¤ë¤Î¤òÂԤäƤ«¤é¡¢
906 ¥»¥Þ¥Õ¥©¤ÎÃͤò 1 ²Ã»»¤¹¤ë½èÍý¤ò¡¢
907 .BR semop ()
908 ¤ò»È¤Ã¤Æ¥¢¥È¥ß¥Ã¥¯ (atomically) ¤Ë¹Ô¤¦¡£
909 .nf
910
911     struct sembuf sops[2];
912     int semid;
913
914     /* Code to set \fIsemid\fP omitted */
915
916     sops[0].sem_num = 0;        /* Operate on semaphore 0 */
917     sops[0].sem_op = 0;         /* Wait for value to equal 0 */
918     sops[0].sem_flg = 0;
919
920     sops[1].sem_num = 0;        /* Operate on semaphore 0 */
921     sops[1].sem_op = 1;         /* Increment value by one */
922     sops[1].sem_flg = 0;
923
924     if (semop(semid, sops, 2) == \-1) {
925         perror("semop");
926         exit(EXIT_FAILURE);
927     }
928 .fi
929 .\"O .SH "SEE ALSO"
930 .SH ´ØÏ¢¹àÌÜ
931 .BR semctl (2),
932 .BR semget (2),
933 .BR sigaction (2),
934 .BR capabilities (7),
935 .BR sem_overview (7),
936 .BR svipc (7),
937 .BR time (7)