3 .\" Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved.
5 .\" @APPLE_LICENSE_HEADER_START@
7 .\" The contents of this file constitute Original Code as defined in and
8 .\" are subject to the Apple Public Source License Version 1.1 (the
9 .\" "License"). You may not use this file except in compliance with the
10 .\" License. Please obtain a copy of the License at
11 .\" http://www.apple.com/publicsource and read it before using this file.
13 .\" This Original Code and all software distributed under the License are
14 .\" distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 .\" EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 .\" INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 .\" FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
18 .\" License for the specific language governing rights and limitations
19 .\" under the License.
21 .\" @APPLE_LICENSE_HEADER_END@
28 .Nd initialize and open a named semaphore
30 .Fd #include <semaphore.h>
32 .Fn sem_open "const char *name" "int flags"
34 .Fn sem_open "const char *name" "int flags" "mode_t mode" "unsigned int value"
36 The named semaphore named
38 is initialized and opened as specified by the argument
40 and a semaphore descriptor is returned to the calling process.
42 The flags specified are formed by
46 .Bd -literal -offset indent -compact
47 O_CREAT create the semaphore if it does not exist
48 O_EXCL error if create and semaphore exists
55 requires an additional two arguments.
57 specifies the permissions for the semaphore as described in
59 and modified by the process' umask value (see
61 The semaphore is created with an initial
63 which must be less than or equal to
68 is specified and the semaphore exists,
70 fails. The check for the existence of the semaphore and the creation
71 of the semaphore are atomic with respect to all processes calling
79 When a new semaphore is created, it is given the user ID and group ID
80 which coorespond to the effective user and group IDs of the calling
81 process. There is no visible entry in the file system for the created
82 object in this implementation.
84 The returned semaphore descriptor is available to the calling process
85 until it is closed with
87 or until the caller exits or execs.
89 If a process makes repeated calls to
93 argument, the same descriptor is returned for each successful call,
96 has been called on the semaphore in the interim.
100 fails for any reason, it will return a value of
104 On success, it returns a semaphore descriptor.
106 The named semaphore is opened unless:
109 The required permissions (for reading and/or writing)
110 are denied for the given flags; or
112 is specified, the object does not exist, and permission to
113 create the semaphore is denied.
118 were specified and the semaphore exists.
122 operation was interrupted by a signal.
126 operation is not supported; or
133 The process has already reached its limit for semaphores or file
135 .It Bq Er ENAMETOOLONG
141 Too many semaphores or file descriptors are open on the system.
144 is not set and the named semaphore does not exist.
147 is specified, the file does not exist, and there is insufficient
148 space available to create the semaphore.
162 is specified in the POSIX Realtime Extension (1003.1b-1993/1003.1i-1995).