2 .\" Hey Emacs! This file is -*- nroff -*- source.
4 .\" Copyright (C) 2006 Michael Kerrisk <mtk.manpages@gmail.com>
6 .\" Permission is granted to make and distribute verbatim copies of this
7 .\" manual provided the copyright notice and this permission notice are
8 .\" preserved on all copies.
10 .\" Permission is granted to copy and distribute modified versions of this
11 .\" manual under the conditions for verbatim copying, provided that the
12 .\" entire resulting derived work is distributed under the terms of a
13 .\" permission notice identical to this one.
15 .\" Since the Linux kernel and libraries are constantly changing, this
16 .\" manual page may be incorrect or out-of-date. The author(s) assume no
17 .\" responsibility for errors or omissions, or for damages resulting from
18 .\" the use of the information contained herein. The author(s) may not
19 .\" have taken the same level of care in the production of this manual,
20 .\" which is licensed free of charge, as they might when working
23 .\" Formatted or processed versions of this manual, if unaccompanied by
24 .\" the source, must acknowledge the copyright and authors of this work.
26 .\" Japanese Version Copyright (c) 2006 Akihiro MOTOKI all rights reserved.
27 .\" Translated 2006-04-18, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
28 .\" Updated 2009-02-23, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>, LDP v3.19
30 .TH SEM_OPEN 3 2009-02-20 "Linux" "Linux Programmer's Manual"
33 .\"O sem_open \- initialize and open a named semaphore
34 sem_open \- ̾Á°ÉÕ¤¥»¥Þ¥Õ¥©¤ò½é´ü²½¤·¡¢¥ª¡¼¥×¥ó¤¹¤ë
38 .BR "#include <fcntl.h>" " /* For O_* constants */"
39 .BR "#include <sys/stat.h>" " /* For mode constants */"
40 .B #include <semaphore.h>
42 .BI "sem_t *sem_open(const char *" name ", int " oflag );
43 .BI "sem_t *sem_open(const char *" name ", int " oflag ", "
44 .BI " mode_t " mode ", unsigned int " value );
47 .\"O Link with \fI\-lrt\fP or \fI\-pthread\fP.
48 \fI\-lrt\fP ¤Þ¤¿¤Ï \fI\-pthread\fP ¤Ç¥ê¥ó¥¯¤¹¤ë¡£
52 .\"O creates a new POSIX semaphore or opens an existing semaphore.
53 .\"O The semaphore is identified by
55 .\"O For details of the construction of
58 .\"O .BR sem_overview (7).
60 ¤Ï¡¢¿·µ¬¤Î POSIX ¥»¥Þ¥Õ¥©¤òºîÀ®¤¹¤ë¤«¡¢´û¸¤Î¥»¥Þ¥Õ¥©¤Î¥ª¡¼¥×¥ó¤ò¹Ô¤¦¡£
71 .\"O argument specifies flags that control the operation of the call.
72 .\"O (Definitions of the flags values can be obtained by including
77 ¤ÎÆ°ºî¤òÀ©¸æ¤¹¤ë¥Õ¥é¥°¤ò»ØÄꤹ¤ë
80 ¤Î¥¤¥ó¥¯¥ë¡¼¥É¤Ë¤è¤êÆÀ¤é¤ì¤ë)¡£
85 .\"O then the semaphore is created if
86 .\"O it does not already exist.
87 .\"O The owner (user ID) of the semaphore is set to the effective
88 .\"O user ID of the calling process.
89 .\"O The group ownership (group ID) is set to the effective group ID
90 .\"O of the calling process.
91 .\"O .\" In reality the file system IDs are used on Linux.
95 ¤¬»ØÄꤵ¤ì¤ë¤È¡¢¤Þ¤À¸ºß¤·¤Ê¤¤¾ì¹ç¤Ë¤Ï¤½¤Î¥»¥Þ¥Õ¥©¤¬ºîÀ®¤µ¤ì¤ë¡£
96 ¥»¥Þ¥Õ¥©¤Î½êÍ¼Ô (¥æ¡¼¥¶ ID)¡¢¥°¥ë¡¼¥×½ê͸¢ (¥°¥ë¡¼¥× ID) ¤Ë¤Ï¡¢
97 ¤½¤ì¤¾¤ì¸Æ¤Ó½Ð¤·¸µ¥×¥í¥»¥¹¤Î¼Â¸ú UID¡¢¼Â¸ú GID ¤¬ÀßÄꤵ¤ì¤ë¡£
98 .\" ¼ÂºÝ¤Ï¡¢Linux ¤Ç¤Ï¥Õ¥¡¥¤¥ë¥·¥¹¥Æ¥à ID ¤¬»ÈÍѤµ¤ì¤ë¡£
103 .\"O are specified in
105 .\"O then an error is returned if a semaphore with the given
113 ¤ÎξÊý¤¬»ØÄꤵ¤ì¤¿¾ì¹ç¡¢»ØÄꤵ¤ì¤¿Ì¾Á°
115 ¤Î¥»¥Þ¥Õ¥©¤¬¤¹¤Ç¤Ë¸ºß¤¹¤ë¤È¥¨¥é¡¼¤¬ÊÖ¤µ¤ì¤ë¡£
121 .\"O then two additional arguments must be supplied.
125 ¤ò»ØÄꤹ¤ë¾ì¹ç¡¢¤µ¤é¤Ë°ú¤¿ô¤¬ 2 ¤ÄɬÍפǤ¢¤ë¡£
128 .\"O argument specifies the permissions to be placed on the new semaphore,
131 .\"O (Symbolic definitions for the permissions bits can be obtained by including
132 .\"O .IR <sys/stat.h> .)
133 .\"O The permissions settings are masked against the process umask.
134 .\"O Both read and write permission should be granted to each class of
135 .\"O user that will access the semaphore.
139 ¤ÈƱ¤¸¤è¤¦¤Ë¡¢¿·¤·¤¤¥»¥Þ¥Õ¥©¤ËÀßÄꤵ¤ì¤ë¥¢¥¯¥»¥¹µö²Ä (permission) ¤ò
140 »ØÄꤹ¤ë¡£µö²ÄÀßÄê¤Ï¥×¥í¥»¥¹¤Î umask ¤Ç¥Þ¥¹¥¯¤µ¤ì¤ë
141 (µö²Ä¥Ó¥Ã¥È¤Î¥·¥ó¥Ü¥ëÄêµÁ¤Ï
143 ¤Î¥¤¥ó¥¯¥ë¡¼¥É¤Ë¤è¤êÆÀ¤é¤ì¤ë)¡£
144 ¥»¥Þ¥Õ¥©¤Ë¥¢¥¯¥»¥¹¤·¤è¤¦¤È¤¹¤ë¥æ¡¼¥¶¤Ï¡¢Æɤ߽Ф·µö²Ä¤È½ñ¤¹þ¤ßµö²Ä¤Î
145 ξÊý¤òÆÀ¤ëɬÍפ¬¤¢¤ë¡£
148 .\"O argument specifies the initial value for the new semaphore.
151 .\"O is specified, and a semaphore with the given
153 .\"O already exists, then
159 °ú¤¿ô¤Ï¿·¤·¤¤¥»¥Þ¥Õ¥©¤Î½é´üÃͤò»ØÄꤹ¤ë¡£
161 ¤¬»ØÄꤵ¤ì¡¢»ØÄꤷ¤¿Ì¾Á°
163 ¤Î¥»¥Þ¥Õ¥©¤¬¤¹¤Ç¤Ë¸ºß¤¹¤ë¾ì¹ç¡¢
168 .\"O .SH RETURN VALUE
172 .\"O returns the address of the new semaphore;
173 .\"O this address is used when calling other semaphore-related functions.
177 .\"O .BR SEM_FAILED ,
180 .\"O set to indicate the error.
183 ¤Ï¿·¤·¤¤¥»¥Þ¥Õ¥©¤Î¥¢¥É¥ì¥¹¤òÊÖ¤¹¡£
184 ¤³¤Î¥¢¥É¥ì¥¹¤Ï¾¤Î¥»¥Þ¥Õ¥©´ØÏ¢¤Î´Ø¿ô¤ò¸Æ¤Ó½Ð¤¹ºÝ¤Ë»ÈÍѤµ¤ì¤ë¡£
191 ¤Ë¥¨¥é¡¼¤ò¼¨¤¹Ãͤò¥»¥Ã¥È¤¹¤ë¡£
196 .\"O The semaphore exists, but the caller does not have permission to
198 ¤½¤Î¥»¥Þ¥Õ¥©¤¬Â¸ºß¤¹¤ë¤¬¡¢¸Æ¤Ó½Ð¤·¸µ¤Ë¤Ï¤½¤Î¥»¥Þ¥Õ¥©¤ò¥ª¡¼¥×¥ó¤¹¤ë
206 .\"O were specified in
208 .\"O but a semaphore with this
216 ¤ÎξÊý¤¬»ØÄꤵ¤ì¤¿¤¬¡¢
218 ¤È¤¤¤¦Ì¾Á°¤Î¥»¥Þ¥Õ¥©¤Ï¤¹¤Ç¤Ë¸ºß¤¹¤ë¡£
222 .\"O was greater than
223 .\"O .BR SEM_VALUE_MAX .
231 .\"O consists of just "/", followed by no other characters.
233 ¤¬ "/" ¤À¤±¤Ç¹½À®¤µ¤ì¡¢¤½¤Î¸å¤í¤Ë¾¤Îʸ»ú¤¬Â³¤¤¤Æ¤¤¤Ê¤«¤Ã¤¿¡£
236 .\"O The process already has the maximum number of files and open.
237 ¥ª¡¼¥×¥ó¤µ¤ì¤¿¥Õ¥¡¥¤¥ë¿ô¤¬¤¹¤Ç¤Ë¤½¤Î¥×¥í¥»¥¹¤Ë¤ª¤±¤ë¾å¸Â¤Ë㤷¤Æ¤¤¤ë¡£
246 .\"O The system limit on the total number of open files has been reached.
247 ¥ª¡¼¥×¥ó¤µ¤ì¤¿¥Õ¥¡¥¤¥ëÁí¿ô¤¬¥·¥¹¥Æ¥àÁ´ÂΤǤξå¸Â¤Ë㤷¤Æ¤¤¤ë¡£
252 .\"O flag was not specified in
254 .\"O and no semaphore with this
260 ¥Õ¥é¥°¤¬»ØÄꤵ¤ì¤Æ¤ª¤é¤º¡¢
262 ¤È¤¤¤¦Ì¾Á°¤Î¥»¥Þ¥Õ¥©¤â¸ºß¤·¤Ê¤¤¡£
265 .\" this error can occur if we have a name of the (nonportable) form
266 .\" /dir/name, and the directory /dev/shm/dir does not exist.
268 .\"O was specified, but
270 .\"O wasn't well formed.
274 ¤¬Å¬ÀڤʷÁ¼°¤Ç¤Ï¤Ê¤«¤Ã¤¿¡£
277 .\"O Insufficient memory.
279 .\"O .SH CONFORMING TO
285 .BR sem_getvalue (3),