3 .\" Wilfredo Sanchez, wsanchez@apple.com
4 .\" Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
6 .\" @APPLE_LICENSE_HEADER_START@
8 .\" The contents of this file constitute Original Code as defined in and
9 .\" are subject to the Apple Public Source License Version 1.1 (the
10 .\" "License"). You may not use this file except in compliance with the
11 .\" License. Please obtain a copy of the License at
12 .\" http://www.apple.com/publicsource and read it before using this file.
14 .\" This Original Code and all software distributed under the License are
15 .\" distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16 .\" EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17 .\" INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18 .\" FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
19 .\" License for the specific language governing rights and limitations
20 .\" under the License.
22 .\" @APPLE_LICENSE_HEADER_END@
29 .Nd initialize and open a named semaphore
31 .Fd #include <semaphore.h>
33 .Fn sem_open "const char *name" "int flags"
35 .Fn sem_open "const char *name" "int flags" "mode_t mode" "unsigned int value"
37 The named semaphore named
39 is initialized and opened as specified by the argument
41 and a semaphore descriptor is returned to the calling process.
43 The flags specified are formed by
47 .Bd -literal -offset indent -compact
48 O_CREAT create the semaphore if it does not exist
49 O_EXCL error if create and semaphore exists
56 requires an additional two arguments.
58 specifies the permissions for the semaphore as described in
60 and modified by the process' umask value (see
62 The semaphore is created with an initial
64 which must be less than or equal to
69 is specified and the semaphore exists,
71 fails. The check for the existence of the semaphore and the creation
72 of the semaphore are atomic with respect to all processes calling
80 When a new semaphore is created, it is given the user ID and group ID
81 which coorespond to the effective user and group IDs of the calling
82 process. There is no visible entry in the file system for the created
83 object in this implementation.
85 The returned semaphore descriptor is available to the calling process
86 until it is closed with
88 or until the caller exits or execs.
90 If a process makes repeated calls to
94 argument, the same descriptor is returned for each successful call,
97 has been called on the semaphore in the interim.
101 fails for any reason, it will return a value of
105 On success, it returns a semaphore descriptor.
107 The named semaphore is opened unless:
110 The required permissions (for reading and/or writing)
111 are denied for the given flags; or
113 is specified, the object does not exist, and permission to
114 create the semaphore is denied.
119 were specified and the semaphore exists.
123 operation was interrupted by a signal.
127 operation is not supported; or
134 The process has already reached its limit for semaphores or file
136 .It Bq Er ENAMETOOLONG
142 Too many semaphores or file descriptors are open on the system.
145 is not set and the named semaphore does not exist.
148 is specified, the file does not exist, and there is insufficient
149 space available to create the semaphore.
163 is specified in the POSIX Realtime Extension (1003.1b-1993/1003.1i-1995).