1 .\" $NetBSD: sem_open.3,v 1.3 2005/01/29 14:19:43 wiz Exp $
3 .\" Copyright (C) 2000 Jason Evans <jasone@FreeBSD.org>.
4 .\" All rights reserved.
6 .\" Redistribution and use in source and binary forms, with or without
7 .\" modification, are permitted provided that the following conditions
9 .\" 1. Redistributions of source code must retain the above copyright
10 .\" notice(s), this list of conditions and the following disclaimer as
11 .\" the first lines of this file unmodified other than the possible
12 .\" addition of one or more copyright notices.
13 .\" 2. Redistributions in binary form must reproduce the above copyright
14 .\" notice(s), this list of conditions and the following disclaimer in
15 .\" the documentation and/or other materials provided with the
18 .\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY
19 .\" EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 .\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE
22 .\" LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 .\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
25 .\" BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 .\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
27 .\" OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
28 .\" EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 .\" From: FreeBSD: src/lib/libc/gen/sem_open.3,v 1.12 2004/07/02 16:45:56 ru
39 .Nd named semaphore operations
45 .Fn sem_open "const char *name" "int oflag" ...
47 .Fn sem_close "sem_t *sem"
49 .Fn sem_unlink "const char *name"
53 function creates or opens the named semaphore specified by
55 The returned semaphore may be used in subsequent calls to
63 The following bits may be set in the
66 .Bl -tag -width ".Dv O_CREAT"
68 Create the semaphore if it does not already exist.
70 The third argument to the call to
74 and specifies the mode for the semaphore.
76 .Dv S_IWUSR , S_IWGRP ,
80 it is not possible to grant only
82 permission on a semaphore.
83 The mode is modified according to the process's file creation
87 The fourth argument must be an
89 and specifies the initial value for the semaphore,
90 and must be no greater than
93 Create the semaphore if it does not exist.
94 If the semaphore already exists,
97 This flag is ignored unless
104 function closes a named semaphore that was opened by a call to
109 function removes the semaphore named
111 Resources allocated to the semaphore are only deallocated when all
112 processes that have the semaphore open close it.
117 function returns the address of the opened semaphore.
120 argument is given to multiple calls to
122 by the same process without an intervening call to
124 the same address is returned each time.
125 If the semaphore cannot be opened,
129 and the global variable
131 is set to indicate the error.
133 .Rv -std sem_close sem_unlink
137 function will fail if:
140 The semaphore exists and the permissions specified by
142 at the time it was created deny access to this process.
144 The semaphore does not exist, but permission to create it is denied.
149 are set but the semaphore already exists.
151 The call was interrupted by a signal.
155 operation is not supported for the given
160 argument is greater than
162 .\"FreeBSD never returns EMFILE
164 .\"Too many semaphores are in use by this process.
165 .It Bq Er ENAMETOOLONG
168 argument is too long.
170 The system limit on semaphores has been reached.
173 is not set and the named semaphore does not exist.
175 There is not enough space to create the semaphore.
180 function will fail if:
185 argument is not a valid semaphore.
190 function will fail if:
193 Permission is denied to unlink the semaphore.
194 .It Bq Er ENAMETOOLONG
199 The named semaphore does not exist.
220 Support for named semaphores first appeared in
223 This implementation places strict requirements on the value of
225 it must begin with a slash
227 contain no other slash characters,
228 and be less than 14 characters in length
229 not including the terminating null character.