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