1 .\" Copyright (C) 2000 Jason Evans <jasone@FreeBSD.org>.
2 .\" All rights reserved.
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\" notice(s), this list of conditions and the following disclaimer as
9 .\" the first lines of this file unmodified other than the possible
10 .\" addition of one or more copyright notices.
11 .\" 2. Redistributions in binary form must reproduce the above copyright
12 .\" notice(s), this list of conditions and the following disclaimer in
13 .\" the documentation and/or other materials provided with the
16 .\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY
17 .\" EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 .\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE
20 .\" LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 .\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23 .\" BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24 .\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
25 .\" OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
26 .\" EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 .\" $FreeBSD: head/lib/libc/gen/sem_open.3 202133 2010-01-12 01:30:05Z davidxu $
37 .Nd named semaphore operations
43 .Fn sem_open "const char *name" "int oflag" ...
45 .Fn sem_close "sem_t *sem"
47 .Fn sem_unlink "const char *name"
51 function creates or opens the named semaphore specified by
53 The returned semaphore may be used in subsequent calls to
61 The following bits may be set in the
64 .Bl -tag -width ".Dv O_CREAT"
66 Create the semaphore if it does not already exist.
68 The third argument to the call to
72 and specifies the mode for the semaphore.
74 .Dv S_IWUSR , S_IWGRP ,
78 The mode is modified according to the process's file creation
82 The fourth argument must be an
84 and specifies the initial value for the semaphore,
85 and must be no greater than
88 Create the semaphore if it does not exist.
89 If the semaphore already exists,
92 This flag is ignored unless
99 function closes a named semaphore that was opened by a call to
104 function removes the semaphore named
106 Resources allocated to the semaphore are only deallocated when all
107 processes that have the semaphore open close it.
108 .Sh IMPLEMENTATION NOTES
109 The current implementation uses shared memory mappings of files.
110 The semaphore files are created at the path pointed to by
118 The environnment variable
119 .Ev LIBTHREAD_SEM_PREFIX
120 can be set to change this value.
122 It is not possible to grant only
124 permission on a semaphore.
129 function returns the address of the opened semaphore.
132 argument is given to multiple calls to
134 by the same process without an intervening call to
136 the same address is returned each time.
137 If the semaphore cannot be opened,
141 and the global variable
143 is set to indicate the error.
144 .Rv -std sem_close sem_unlink
148 function will fail if:
151 The semaphore exists and the permissions specified by
153 at the time it was created deny access to this process.
155 The semaphore does not exist and permission to create it is denied.
160 are set but the semaphore already exists.
162 The call was interrupted by a signal.
166 operation is not supported for the given
171 argument is greater than
174 Too many filedescriptors are in use by this process.
175 .It Bq Er ENAMETOOLONG
178 argument is too long or a pathname component is too long.
180 The system limit on semaphores or open files has been reached.
183 is not set but the named semaphore does not exist.
185 There is not enough space to create the semaphore.
187 There is insufficient memory for the creation of the new named semaphore.
192 function will fail if:
197 argument is not a valid semaphore.
202 function will fail if:
205 Permission is denied to unlink the semaphore.
206 .It Bq Er ENAMETOOLONG
209 is too long or a pathname component is too long.
211 The named semaphore does not exist.
231 Support for named semaphores first appeared in