]>
Commit | Line | Data |
---|---|---|
e9ce8d39 A |
1 | .\" $Darwin$ |
2 | .\" | |
5b2abdfb | 3 | .\" Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved. |
e9ce8d39 A |
4 | .\" |
5 | .\" @APPLE_LICENSE_HEADER_START@ | |
6 | .\" | |
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. | |
12 | .\" | |
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. | |
20 | .\" | |
21 | .\" @APPLE_LICENSE_HEADER_END@ | |
22 | .\" | |
23 | .Dd June 8, 2000 | |
24 | .Dt SEM_OPEN 2 | |
25 | .Os Darwin | |
26 | .Sh NAME | |
27 | .Nm sem_open | |
28 | .Nd initialize and open a named semaphore | |
29 | .Sh SYNOPSIS | |
30 | .Fd #include <semaphore.h> | |
31 | .Ft sem_t * | |
224c7076 A |
32 | .Fo sem_open |
33 | .Fa "const char *name" | |
34 | .Fa "int oflag" | |
35 | .Fa "..." | |
36 | .Fc | |
37 | .Pp | |
38 | The parameters "mode_t mode" and "unsigned int value" | |
39 | are optional. | |
e9ce8d39 A |
40 | .Sh DESCRIPTION |
41 | The named semaphore named | |
42 | .Fa name | |
43 | is initialized and opened as specified by the argument | |
224c7076 | 44 | .Fa oflag |
e9ce8d39 A |
45 | and a semaphore descriptor is returned to the calling process. |
46 | .Pp | |
224c7076 A |
47 | The value of |
48 | .Fa oflag | |
49 | is formed by | |
e9ce8d39 A |
50 | .Em or Ns 'ing |
51 | the following values: | |
52 | .Pp | |
53 | .Bd -literal -offset indent -compact | |
54 | O_CREAT create the semaphore if it does not exist | |
55 | O_EXCL error if create and semaphore exists | |
56 | .Ed | |
57 | .Pp | |
58 | If | |
224c7076 A |
59 | .Dv O_CREAT |
60 | is specified, | |
e9ce8d39 A |
61 | .Fn sem_open |
62 | requires an additional two arguments. | |
63 | .Fa mode | |
64 | specifies the permissions for the semaphore as described in | |
65 | .Xr chmod 2 | |
66 | and modified by the process' umask value (see | |
67 | .Xr umask 2 ) . | |
68 | The semaphore is created with an initial | |
69 | .Fa value , | |
70 | which must be less than or equal to | |
71 | .Dv SEM_VALUE_MAX . | |
72 | .Pp | |
73 | If | |
74 | .Dv O_EXCL | |
75 | is specified and the semaphore exists, | |
76 | .Fn sem_open | |
77 | fails. The check for the existence of the semaphore and the creation | |
78 | of the semaphore are atomic with respect to all processes calling | |
79 | .Fn sem_open | |
80 | with | |
81 | .Dv O_CREAT | |
82 | and | |
83 | .Dv O_EXCL | |
84 | set. | |
85 | .Pp | |
86 | When a new semaphore is created, it is given the user ID and group ID | |
224c7076 | 87 | which correspond to the effective user and group IDs of the calling |
e9ce8d39 A |
88 | process. There is no visible entry in the file system for the created |
89 | object in this implementation. | |
90 | .Pp | |
91 | The returned semaphore descriptor is available to the calling process | |
92 | until it is closed with | |
93 | .Fn sem_close , | |
94 | or until the caller exits or execs. | |
95 | .Pp | |
96 | If a process makes repeated calls to | |
97 | .Fn sem_open , | |
98 | with the same | |
99 | .Fa name | |
100 | argument, the same descriptor is returned for each successful call, | |
101 | unless | |
102 | .Fn sem_unlink | |
103 | has been called on the semaphore in the interim. | |
104 | .Pp | |
105 | If | |
106 | .Fn sem_open | |
107 | fails for any reason, it will return a value of | |
108 | .Dv SEM_FAILED | |
109 | and sets | |
110 | .Va errno . | |
111 | On success, it returns a semaphore descriptor. | |
112 | .Sh ERRORS | |
113 | The named semaphore is opened unless: | |
114 | .Bl -tag -width Er | |
115 | .It Bq Er EACCES | |
116 | The required permissions (for reading and/or writing) | |
117 | are denied for the given flags; or | |
118 | .Dv O_CREAT | |
119 | is specified, the object does not exist, and permission to | |
120 | create the semaphore is denied. | |
121 | .It Bq Er EEXIST | |
122 | .Dv O_CREAT | |
123 | and | |
124 | .Dv O_EXCL | |
125 | were specified and the semaphore exists. | |
126 | .It Bq Er EINTR | |
127 | The | |
128 | .Fn sem_open | |
129 | operation was interrupted by a signal. | |
130 | .It Bq Er EINVAL | |
131 | The | |
132 | .Fn shm_open | |
133 | operation is not supported; or | |
134 | .Dv O_CREAT | |
135 | is specified and | |
136 | .Fa value | |
137 | exceeds | |
138 | .Dv SEM_VALUE_MAX . | |
139 | .It Bq Er EMFILE | |
140 | The process has already reached its limit for semaphores or file | |
141 | descriptors in use. | |
142 | .It Bq Er ENAMETOOLONG | |
143 | .Fa name | |
144 | exceeded | |
145 | .Dv SEM_NAME_LEN | |
146 | characters. | |
147 | .It Bq Er ENFILE | |
148 | Too many semaphores or file descriptors are open on the system. | |
149 | .It Bq Er ENOENT | |
150 | .Dv O_CREAT | |
151 | is not set and the named semaphore does not exist. | |
152 | .It Bq Er ENOSPC | |
153 | .Dv O_CREAT | |
154 | is specified, the file does not exist, and there is insufficient | |
155 | space available to create the semaphore. | |
156 | .El | |
157 | .Sh SEE ALSO | |
e9ce8d39 A |
158 | .Xr sem_close 2 , |
159 | .Xr sem_post 2 , | |
160 | .Xr sem_trywait 2 , | |
161 | .Xr sem_unlink 2 , | |
162 | .Xr sem_wait 2 , | |
224c7076 A |
163 | .Xr semctl 2 , |
164 | .Xr semget 2 , | |
165 | .Xr semop 2 , | |
e9ce8d39 A |
166 | .Xr umask 2 |
167 | .Sh HISTORY | |
168 | .Fn sem_open | |
169 | is specified in the POSIX Realtime Extension (1003.1b-1993/1003.1i-1995). |