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 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.
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
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
52 .\"WORD: implement ¼ÂÁõ
54 .\"WORD: free ²òÊü(free).
55 .\"WORD: memory ¥á¥â¥ê
56 .\"WORD: anonymous structure ̵̾¹½Â¤ÂÎ
57 .\"WORD: time limit À©¸Â»þ´Ö
59 .TH SEMOP 2 2008-10-04 "Linux" "Linux Programmer's Manual"
62 .\"O semop, semtimedop \- semaphore operations
63 semop, semtimedop \- ¥»¥Þ¥Õ¥©¤ÎÁàºî
67 .B #include <sys/types.h>
68 .B #include <sys/ipc.h>
69 .B #include <sys/sem.h>
71 .BI "int semop(int " semid ", struct sembuf *" sops ", unsigned " nsops );
73 .BI "int semtimedop(int " semid ", struct sembuf *" sops ", unsigned " nsops ,
74 .BI " struct timespec *" timeout );
78 .\"O Feature Test Macro Requirements for glibc (see
79 .\"O .BR feature_test_macros (7)):
80 glibc ¸þ¤±¤Îµ¡Ç½¸¡ºº¥Þ¥¯¥í¤ÎÍ×·ï
81 .RB ( feature_test_macros (7)
89 .\"O Each semaphore in a semaphore set has the following associated values:
90 ¥»¥Þ¥Õ¥©½¸¹ç (semaphore set) ¤Î¥á¥ó¥Ð¡¼¤Î³Æ¥»¥Þ¥Õ¥©¤Ï
91 °Ê²¼¤Î´ØÏ¢¾ðÊó¤ò»ý¤Ã¤Æ¤¤¤ë:
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; /* ºÇ¸å¤ËÁàºî¤ò¹Ô¤Ê¤Ã¤¿¥×¥í¥»¥¹ */
107 .\"O performs operations on selected semaphores in the set indicated by
112 ¤Ç»ØÄꤵ¤ì¤¿¥»¥Þ¥Õ¥©½¸¹ç¤ÎÁªÂò¤µ¤ì¤¿¥»¥Þ¥Õ¥©¤ËÂФ·¤ÆÁàºî¤ò¹Ô¤¦¡£
115 .\"O elements in the array pointed to by
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:
124 ¸Ä¤ÎÍ×ÁǤÎÇÛÎó¤ò»Ø¤·¡¢ÇÛÎó¤Î³ÆÍ×ÁǤϸġ¹¤Î¥»¥Þ¥Õ¥©¤Ë
125 ÂФ¹¤ëÁàºî¤ò¼¨¤¹¡£¤½¤Î·¿¤Ï
127 ¤Ç¡¢¼¡¤Î¥á¥ó¥Ð¤ò»ý¤Ä:
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; /* Áàºî¥Õ¥é¥° */
140 .\"O Flags recognized in
146 .\"O If an operation specifies
148 .\"O it will be automatically undone when the process terminates.
156 ¤¬»ØÄꤵ¤ì¤¿Áàºî¤Ï¡¢¤½¤Î¥×¥í¥»¥¹¤¬½ªÎ»¤·¤¿»þ¤Ë¼«Æ°Åª¤Ë¼è¤ê¾Ã¤µ¤ì¤ë¡£
158 .\"O The set of operations contained in
161 .\"O .IR "array order" ,
163 .\"O .IR atomically ,
164 .\"O that is, the operations are performed either as a complete unit,
167 ¤Ë´Þ¤Þ¤ì¤ëÁàºî¤Î½¸¹ç¤Ï¡¢
172 ¤¹¤Ê¤ï¤Á¡¢Á´¤Æ¤ÎÁàºî¤¬´°Á´¤Ë¼Â¹Ô¤µ¤ì¤ë¤«¡¢Á´¤¯¼Â¹Ô¤µ¤ì¤Ê¤¤¤«¤Î
175 .\"O The behavior of the system call if not all operations can be
176 .\"O performed immediately depends on the presence of the
178 .\"O flag in the individual
180 .\"O fields, as noted below.
181 Á´¤Æ¤ÎÁàºî¤¬Ä¾¤Á¤Ë¼Â¹Ô¤Ç¤¤Ê¤¤¾ì¹ç¤Î¤³¤Î¥·¥¹¥Æ¥à¥³¡¼¥ë¤Î¿¶¤ëÉñ¤¤¤Ï
186 ¤¬Â¸ºß¤¹¤ë¤«¤Ë¤è¤Ã¤Æ·è¤Þ¤ê¡¢¸å½Ò¤Î¤è¤¦¤Ë¤Ê¤ë¡£
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
192 ¤½¤ì¤¾¤ì¤ÎÁàºî¤Ï¥»¥Þ¥Õ¥©½¸¹ç¤Î
194 ¤Î¥»¥Þ¥Õ¥©¤ËÂФ·¤Æ¼Â¹Ô¤µ¤ì¤ë¡£¥»¥Þ¥Õ¥©½¸¹ç¤ÎºÇ½é¤Î¥»¥Þ¥Õ¥©¤Ë¤Ï
196 .\"O There are three types of operation, distinguished by the value of
198 ¤½¤·¤ÆÁàºî¤Ï»°¼ïÎढ¤ê¡¢
204 .\"O is a positive integer, the operation adds this value to
205 .\"O the semaphore value
209 .\"O is specified for this operation, the system updates the process undo count
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.
215 ¤¬Àµ¤ÎÀ°¿ô¤Î¾ì¹ç¡¢Áàºî¤È¤·¤Æ¤½¤ÎÃͤò¥»¥Þ¥Õ¥©¤ÎÃÍ
217 ¤Ë²Ã¤¨¤ë¡£¤µ¤é¤Ë¤³¤ÎÁàºî¤Ë
219 ¤¬»ØÄꤵ¤ì¤Æ¤¤¤ë¾ì¹ç¤Ï¡¢¥·¥¹¥Æ¥à¤Ï¤³¤Î¥»¥Þ¥Õ¥©¤Î ¥×¥í¥»¥¹¡¦¥¢¥ó¥É¥¥¿ô
222 ¤³¤ÎÁàºî¤Ïɬ¤º¼Â¹Ô¤Ç¤¡¢¥×¥í¥»¥¹¤ÎÄä»ß¤Ïµ¯¤³¤é¤Ê¤¤¡£
223 ¸Æ¤Ó½Ð¤·¸µ¥×¥í¥»¥¹¤ÏÂоݤΥ»¥Þ¥Õ¥©½¸¹ç¤òÊѹ¹¤¹¤ëµö²Ä¤¬¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£
227 .\"O is zero, the process must have read permission on the semaphore
229 .\"O This is a "wait-for-zero" operation: if
231 .\"O is zero, the operation can immediately proceed.
233 ¤¬ 0 ¤Î¾ì¹ç¡¢¡Ö¥¼¥í¤Þ¤ÇÂԤġ×Áàºî¤Ç¤¢¤ë¡£¤³¤Î¾ì¹ç¡¢¥×¥í¥»¥¹¤Ï
234 ¤½¤Î¥»¥Þ¥Õ¥©½¸¹ç¤ËÂФ¹¤ëÆɤ߹þ¤ßµö²Ä¤¬¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£
236 ¤¬ 0 ¤Ê¤é¤Ð¡¢Áàºî¤Ïľ¤Á¤Ë¹Ô¤ï¤ì¤ë¡£
246 .\"O (and none of the operations in
260 ¤¬ÀßÄꤵ¤ì¤ë (¤³¤Î¤È¤
262 ¤ËÂФ¹¤ëÁàºî¤ÏÁ´¤¯¼Â¹Ô¤µ¤ì¤Ê¤¤)¡£
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:
271 ¤¬»ØÄꤵ¤ì¤Æ¤¤¤Ê¤¤¾ì¹ç¡¢
273 (¥»¥Þ¥Õ¥©Ãͤ¬ 0 ¤Ë¤Ê¤ë¤Î¤òÂԤäƤ¤¤ë¥×¥í¥»¥¹¤Î¿ô) ¤ò 1 Áý²Ã¤µ¤»¤Æ¡¢
274 °Ê²¼¤Î¤¤¤º¤ì¤«¤¬µ¯¤³¤ë¤Þ¤Ç¥×¥í¥»¥¹¤òÄä»ß (sleep) ¤¹¤ë¡£
277 .\"O becomes 0, at which time the value of
281 ¤¬ 0 ¤Ë¤Ê¤Ã¤¿: ¤³¤Î¤È¤
283 ¤ÎÃÍ¤Ï 1 ¸º»»¤µ¤ì¤ë¡£
285 .\"O The semaphore set
292 ¥»¥Þ¥Õ¥©½¸¹ç¤¬ºï½ü¤µ¤ì¤¿: ¤³¤Î¤È¤
300 .\"O The calling process catches a signal:
303 .\"O is decremented and
309 ¸Æ¤Ó½Ð¤·¸µ¥×¥í¥»¥¹¤¬¥·¥°¥Ê¥ë¤òÊá³Í¤·¤¿: ¤³¤Î¤È¤
319 .\"O The time limit specified by
322 .\"O .BR semtimedop ()
329 .\" motoki: semop () ¤Ï semtimedop () ¤Î´Ö°ã¤¤¡©
333 ¤Ç»ØÄꤵ¤ì¤¿À©¸Â»þ´Ö¤¬·Ð²á¤·¤¿: ¤³¤Î¤È¤
343 .\"O is less than zero, the process must have alter permission on the
347 .\"O is greater than or equal to the absolute value of
349 .\"O the operation can proceed immediately:
350 .\"O the absolute value of
352 .\"O is subtracted from
356 .\"O is specified for this operation, the system updates the process undo count
358 .\"O for this semaphore.
360 ¤¬ 0 ̤Ëþ¤Î¾ì¹ç¡¢¥×¥í¥»¥¹¤Ë¤Ï¤½¤Î¥»¥Þ¥Õ¥©½¸¹ç¤òÊѹ¹¤¹¤ëµö²Ä¤¬¤Ê¤±¤ì¤Ð
365 ¤ÎÀäÂÐÃͰʾå¤Î¾ì¹ç¤Ï¡¢Áàºî¤Ïľ¤Á¤Ë¼Â¹Ô¤µ¤ì¤ë:
369 ¤ÎÀäÂÐÃͤ¬¸º»»¤µ¤ì¤ë¡£
372 ¤¬»ØÄꤵ¤ì¤Æ¤¤¤ë¾ì¹ç¤Ï¡¢¤³¤Î¥»¥Þ¥Õ¥©¤Î¥×¥í¥»¥¹¡¦¥¢¥ó¥É¥¥¿ô
375 .\"O If the absolute value of
388 .\"O (and none of the operations in
404 ¤¬ÀßÄꤵ¤ì¤ë (¤³¤Î¤È¤
406 ¤ÎÁàºî¤ÏÁ´¤¯¼Â¹Ô¤µ¤ì¤Ê¤¤)¡£
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:
413 ¤¬»ØÄꤵ¤ì¤Æ¤¤¤Ê¤±¤ì¤Ð¡¢
415 (¤³¤Î¥»¥Þ¥Õ¥©¤ÎÃͤ¬Áý²Ã¤¹¤ë¤Î¤òÂԤäƤ¤¤ë¥×¥í¥»¥¹¿ô¤Î¥«¥¦¥ó¥¿)
416 ¤ò 1 Áý²Ã¤µ¤»¤Æ¡¢°Ê²¼¤Î¤¤¤º¤ì¤«¤¬µ¯¤³¤ë¤Þ¤Ç¥×¥í¥»¥¹¤òÄä»ß (sleep) ¤¹¤ë¡£
419 .\"O becomes greater than or equal to the absolute value of
421 .\"O at which time the value of
423 .\"O is decremented, the absolute value of
425 .\"O is subtracted from
429 .\"O is specified for this operation, the system updates the process undo count
431 .\"O for this semaphore.
435 ¤ÎÀäÂÐÃͰʾå¤Ë¤Ê¤Ã¤¿: ¤³¤Î¤È¤
444 ¤¬»ØÄꤵ¤ì¤Æ¤¤¤¿¾ì¹ç¤Ë¤Ï¤³¤Î¥»¥Þ¥Õ¥©¤Î¥×¥í¥»¥¹¡¦¥¢¥ó¥É¥¥¿ô
448 .\"O The semaphore set is removed from the system:
454 ¥»¥Þ¥Õ¥©½¸¹ç¤¬¥·¥¹¥Æ¥à¤«¤éºï½ü¤µ¤ì¤¿: ¤³¤Î¤È¤
462 .\"O The calling process catches a signal:
465 .\"O is decremented and
471 ¸Æ¤Ó½Ð¤·¤¿¥×¥í¥»¥¹¤¬¥·¥°¥Ê¥ë¤òÊá³Í¤·¤¿: ¤³¤Î¤È¤
481 .\"O The time limit specified by
484 .\"O .BR semtimedop ()
485 .\"O call expires: the system call fails, with
489 .\" motoki: the system call ¤Ï semtimedop () ¤Î¤³¤È¡©
493 ¤Ç»ØÄꤵ¤ì¤¿À©¸Â»þ´Ö¤¬·Ð²á¤·¤¿: ¤³¤Î¤È¤
501 .\"O On successful completion, the
503 .\"O value for each semaphore specified in the array pointed to by
505 .\"O is set to the process ID of the calling process.
508 ¤¬»Ø¤¹ÇÛÎó¤Ë¤è¤Ã¤ÆÁàºîÂоݤȤʤ俳ƥ»¥Þ¥Õ¥©¤Î
510 ¥á¥ó¥Ð¡¼¤Ë¤Ï¸Æ¤Ó½Ð¤·¤¿¥×¥í¥»¥¹¤Î¥×¥í¥»¥¹ ID ¤¬ÀßÄꤵ¤ì¤ë¡£
511 .\"O In addition, the
514 .\"O .\" .I sem_ctime
515 .\"O is set to the current time.
520 ¤Ë¸½ºß»þ¹ï¤¬ÀßÄꤵ¤ì¤ë¡£
523 .\"O .BR semtimedop ()
524 .\"O behaves identically to
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
530 .\"O structure whose address is passed in the
537 ¸Æ¤Ó½Ð¤·¸µ¥×¥í¥»¥¹¤¬Ää»ß¤¹¤ë¾ì¹ç¡¢Ää»ß´ü´Ö¤Î¾å¸Â¤¬
541 ¹½Â¤ÂΤǻØÄꤵ¤ì¤¿»þ´Ö¤È¤Ê¤ëÅÀ¤À¤±¤¬°Û¤Ê¤ë¡£
542 .\"O If the specified time limit has been reached,
543 .\"O .BR semtimedop ()
548 .\"O (and none of the operations in
551 »ØÄꤷ¤¿À©¸Â»þ´Ö¤Ë㤷¤¿¾ì¹ç¤Ï¡¢
560 ¤ÎÁàºî¤Ï¼Â¹Ô¤µ¤ì¤Ê¤¤)¡£
563 .\"O argument is NULL,
565 .\"O .BR semtimedop ()
566 .\"O behaves exactly like
569 °ú¤¿ô¤¬ NULL ¤Î¾ì¹ç¡¢
573 ´Ø¿ô¤ÈÁ´¤¯Æ±¤¸¤Ë¤Ê¤ë¡£
574 .\"O .SH "RETURN VALUE"
579 .\"O .BR semtimedop ()
581 .\"O otherwise they return \-1
584 .\"O indicating the error.
589 ¤Ï 0 ¤òÊÖ¤¹¡£¤½¤¦¤Ç¤Ê¤±¤ì¤Ð \-1 ¤òÊÖ¤·¡¢
597 .\"O is set to one of the following:
600 ¤Ë°Ê²¼¤Î¤É¤ì¤«¤¬ÀßÄꤵ¤ì¤ë:
607 .\"O the maximum number of operations allowed per system
614 ¤Ï°ì²ó¤Î¥·¥¹¥Æ¥à¥³¡¼¥ë¤Çµö¤µ¤ì¤ëÁàºî¤ÎºÇÂç¸Ä¿ô¤Ç¤¢¤ë¡£
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
622 ¸Æ¤Ó½Ð¤·¸µ¥×¥í¥»¥¹¤Ë¤Ï»ØÄꤵ¤ì¤¿¥»¥Þ¥Õ¥©Áàºî¤ò¹Ô¤¦¤Î¤Ë
623 ɬÍפʥ¢¥¯¥»¥¹µö²Ä¤¬¤Ê¤¯¡¢
625 ¥±¡¼¥Ñ¥Ó¥ê¥Æ¥£¤â¤Ê¤¤¡£
628 .\"O An operation could not proceed immediately and either
630 .\"O was specified in
632 .\"O or the time limit specified in
635 Áàºî¤òľ¤Á¤Ë½èÍý¤¹¤ë¤³¤È¤¬¤Ç¤¤º¡¢¤«¤Ä
641 ¤Ç»ØÄꤵ¤ì¤¿À©¸Â»þ´Ö¤¬·Ð²á¤·¤¿¡£
644 .\"O An address specified in either the
648 .\"O arguments isn't accessible.
653 ¤¬»Ø¤·¤Æ¤¤¤ë¥¢¥É¥ì¥¹¤Ë¥¢¥¯¥»¥¹¤Ç¤¤Ê¤¤¡£
656 .\"O For some operation the value of
658 .\"O is less than 0 or greater than or equal to the number
659 .\"O of semaphores in the set.
662 ¤ÎÃͤ¬ 0 ̤Ëþ¤«¡¢½¸¹çÆâ¤Î¥»¥Þ¥Õ¥©¤Î¿ô°Ê¾å¤Ç¤¢¤ë¡£
665 .\"O The semaphore set was removed.
666 ¥»¥Þ¥Õ¥©½¸¹ç¤¬ºï½ü¤µ¤ì¤¿¡£
669 .\"O While blocked in this system call, the process caught a signal; see
671 ¤³¤Î¥·¥¹¥Æ¥à¥³¡¼¥ë¤ÇÄä»ß¤·¤Æ¤¤¤ë»þ¤Ë¥×¥í¥»¥¹¤¬¥·¥°¥Ê¥ë¤òÊá³Í¤·¤¿¡£
676 .\"O The semaphore set doesn't exist, or
678 .\"O is less than zero, or
680 .\"O has a nonpositive value.
681 ¥»¥Þ¥Õ¥©½¸¹ç¤¬Â¸ºß¤·¤Ê¤¤¤«¡¢
690 .\"O of some operation specified
692 .\"O and the system does not have enough memory to allocate the undo
698 ¤¬»ØÄꤵ¤ì¤¿¤¬¡¢¥·¥¹¥Æ¥à¤Ë¥¢¥ó¥É¥¥¹½Â¤ÂΤ˳ä¤êÅö¤Æ¤ë½½Ê¬¤Ê¥á¥â¥ê¤¬¤Ê¤¤¡£
701 .\"O For some operation
702 .\"O .I sem_op+semval
705 .\"O the implementation dependent maximum value for
715 ¤ÎºÇÂçÃͤǡ¢¤½¤ÎÃͤϼÂÁõ°Í¸¤Ç¤¢¤ë¡£
718 .\"O .BR semtimedop ()
719 .\"O first appeared in Linux 2.5.52,
720 .\"O and was subsequently backported into kernel 2.4.22.
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.
728 ¤Î glibc ¤Ç¤Î¥µ¥Ý¡¼¥È¤Ï¥Ð¡¼¥¸¥ç¥ó 2.3.3 ¤Ç½é¤á¤ÆÅо줷¤¿¡£
729 .\"O .SH "CONFORMING TO"
732 .\"O .\" SVr4 documents additional error conditions EINVAL, EFBIG, ENOSPC.
733 .\" SVr4 ¤Ë¤Ï¡¢ÄÉ²Ã¤Ç EINVAL, EFBIG, ENOSPC ¤Î¥¨¥é¡¼¾õÂ֤ˤĤ¤¤Æ¤Î
739 .\"O structures of a process aren't inherited by the child produced by
741 .\"O but they are inherited across an
748 ¤ÇÀ¸À®¤µ¤ì¤¿»Ò¥×¥í¥»¥¹¤Ë¤Ï·Ñ¾µ¤µ¤ì¤Ê¤¤¤¬¡¢
750 ¥·¥¹¥Æ¥à¥³¡¼¥ë¤Î¾ì¹ç¤Ï·Ñ¾µ¤µ¤ì¤ë¡£
753 .\"O is never automatically restarted after being interrupted by a signal handler,
754 .\"O regardless of the setting of the
756 .\"O flag when establishing a signal handler.
758 ¤Ï¥·¥°¥Ê¥ë¥Ï¥ó¥É¥é¤Ë¤è¤Ã¤ÆÃæÃǤµ¤ì¤¿¸å¤Ë¡¢
759 ·è¤·¤Æ¼«Æ°Åª¤ËºÆ³«¤¹¤ë¤³¤È¤Ï¤Ê¤¤¡£
760 ¤¿¤È¤¨¥·¥°¥Ê¥ë¥Ï¥ó¥É¥é¤ÎÀßÄê»þ¤Ë
762 ¥Õ¥é¥°¤¬¥»¥Ã¥È¤µ¤ì¤Æ¤¤¤Æ¤âºÆ³«¤¹¤ë¤³¤È¤Ï¤Ê¤¤
765 .\"O is a per-process integer which is simply the (negative) count
766 .\"O of all semaphore operations performed specifying the
770 ¤Ï¥×¥í¥»¥¹¤´¤È¤ÎÀ°¿ô¤Ç¡¢
772 ¥Õ¥é¥°¤òÀßÄꤷ¤Æ¼Â¹Ô¤µ¤ì¤¿Á´¤Æ¤Î¥»¥Þ¥Õ¥©Áàºî¤Î(Éé¿ô¤Î)¥«¥¦¥ó¥¿¤Ç¤¢¤ë¡£
773 .\"O When a semaphore's value is directly set using the
779 .\"O the corresponding
781 .\"O values in all processes are cleared.
787 ¤ò»ØÄꤷ¡¢¥»¥Þ¥Õ¥©¤ÎÃͤ¬
788 ľÀÜÀßÄꤵ¤ì¤¿¾ì¹ç¤Ë¤Ï¡¢Á´¤Æ¤Î¥×¥í¥»¥¹¤Ë¤ª¤¤¤ÆÂбþ¤¹¤ë
792 .\"O The \fIsemval\fP, \fIsempid\fP, \fIsemzcnt\fP, and \fIsemnct\fP values
793 .\"O for a semaphore can all be retrieved using appropriate
796 ¤¢¤ë¥»¥Þ¥Õ¥©¤Î \fIsemval\fP, \fIsempid\fP, \fIsemzcnt\fP, \fIsemnct\fP
797 ¤ÎÃͤϤ¤¤º¤ì¤â¡¢Å¬ÀÚ¤ÊÁàºî¤ò»ØÄꤷ¤Æ
799 ¤ò¸Æ¤Ó½Ð¤¹¤³¤È¤Ç¼èÆÀ¤Ç¤¤ë¡£
801 .\"O The following limits on semaphore set resources affect the
804 ¥»¥Þ¥Õ¥©½¸¹ç¤Î¥ê¥½¡¼¥¹¤Ë´Ø¤¹¤ëÀ©¸Â¤Î¤¦¤Á¡¢
806 ¤Ë±Æ¶Á¤òµÚ¤Ü¤¹¤â¤Î¤ò°Ê²¼¤Ëµó¤²¤ë:
809 .\"O Maximum number of operations allowed for one
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
817 ¤Çµö¤µ¤ì¤ëÁàºî¤ÎºÇÂç¿ô (32)¡£
818 (Linux ¤Ç¤Ï¡¢¤³¤ÎÀ©¸ÂÃͤÏ
819 .I /proc/sys/kernel/sem
820 ¤ÎÂè3¥Õ¥£¡¼¥ë¥É¤ËÂбþ¤·¡¢Æɤ߽Ф·¤âÊѹ¹¤â¤Ç¤¤ë)¡£
821 .\" ¤³¤Î /proc ¥Õ¥¡¥¤¥ë¤Ï Linux 2.2 °ÊÁ°¤Ç¤ÏÍøÍѤǤ¤Ê¤¤ -- MTK
824 .\"O Maximum allowable value for
826 .\"O implementation dependent (32767).
828 ¤¬¼è¤êÆÀ¤ëºÇÂçÃÍ: ¼ÂÁõ°Í¸ (32767)¡£
830 .\"O The implementation has no intrinsic limits for
831 .\"O the adjust on exit maximum value
833 .\"O the system wide maximum number of undo structures
835 .\"O and the per-process maximum number of undo entries system parameters.
836 °Ê²¼¤ÎÃͤ˴ؤ·¤Æ¤Ï¼ÂÁõ°Í¸¤ÎÀ©¸Â¤Ï¤Ê¤¤¡£
837 ½ªÎ»»þ¤ÎÄ´À° (adjust on exit) ¤ÎºÇÂçÃÍ
839 ¥·¥¹¥Æ¥àÁ´ÂΤΥ¢¥ó¥É¥¥¹½Â¤ÂΤκÇÂç¿ô
841 ¥×¥í¥»¥¹¤¢¤¿¤ê¤Î¥¢¥ó¥É¥¥¹½Â¤ÂΤκÇÂç¿ô¡£
844 .\"O When a process terminates, its set of associated
846 .\"O structures is used to undo the effect of all of the
847 .\"O semaphore operations it performed with the
850 ¥×¥í¥»¥¹¤¬½ªÎ»¤¹¤ëºÝ¡¢¥×¥í¥»¥¹¤ËÂбþ¤¹¤ë
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
872 .\"O is specified for a semaphore operation).
873 Ê̤ÎÁªÂò»è¤È¤·¤Æ¡¢¤³¤Î¤è¤¦¤Ê¥»¥Þ¥Õ¥©Ä´À°¤ò´°Á´¤Ë̵»ë¤·¤Æ¤·¤Þ¤¦ÊýË¡¤¬¤¢¤ë
874 (¤³¤ì¤Ï¥»¥Þ¥Õ¥©Áàºî¤È¤·¤Æ
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 ¤Þ¤Ç) ¸º¾¯¤µ¤»¤Æ¡¢¥×¥í¥»¥¹¤Î½ªÎ»¤òľ¤Á¤Ë³¹Ô¤Ç¤¤ë¤è¤¦¤Ë¤·¤Æ¤¤¤ë¡£
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
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 ¤Ç½¤Àµ¤µ¤ì¤Æ¤¤¤ë¡£
895 .\" http://marc.theaimsgroup.com/?l=linux-kernel&m=110260821123863&w=2
897 .\" http://marc.theaimsgroup.com/?l=linux-kernel&m=110261701025794&w=2
900 .\"O The following code segment uses
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 ²Ã»»¤¹¤ë½èÍý¤ò¡¢
908 ¤ò»È¤Ã¤Æ¥¢¥È¥ß¥Ã¥¯ (atomically) ¤Ë¹Ô¤¦¡£
911 struct sembuf sops[2];
914 /* Code to set \fIsemid\fP omitted */
916 sops[0].sem_num = 0; /* Operate on semaphore 0 */
917 sops[0].sem_op = 0; /* Wait for value to equal 0 */
920 sops[1].sem_num = 0; /* Operate on semaphore 0 */
921 sops[1].sem_op = 1; /* Increment value by one */
924 if (semop(semid, sops, 2) == \-1) {
934 .BR capabilities (7),
935 .BR sem_overview (7),