2 .\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for
3 .\" permission to reproduce portions of its copyrighted documentation.
4 .\" Original documentation from The Open Group can be obtained online at
5 .\" http://www.opengroup.org/bookstore/.
7 .\" The Institute of Electrical and Electronics Engineers and The Open
8 .\" Group, have given us permission to reprint portions of their
11 .\" In the following statement, the phrase ``this text'' refers to portions
12 .\" of the system documentation.
14 .\" Portions of this text are reprinted and reproduced in electronic form
15 .\" in the SunOS Reference Manual, from IEEE Std 1003.1, 2004 Edition,
16 .\" Standard for Information Technology -- Portable Operating System
17 .\" Interface (POSIX), The Open Group Base Specifications Issue 6,
18 .\" Copyright (C) 2001-2004 by the Institute of Electrical and Electronics
19 .\" Engineers, Inc and The Open Group. In the event of any discrepancy
20 .\" between these versions and the original IEEE and The Open Group
21 .\" Standard, the original IEEE and The Open Group Standard is the referee
22 .\" document. The original Standard can be obtained online at
23 .\" http://www.opengroup.org/unix/online.html.
25 .\" This notice shall appear on any product containing this material.
27 .\" The contents of this file are subject to the terms of the
28 .\" Common Development and Distribution License (the "License").
29 .\" You may not use this file except in compliance with the License.
31 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
32 .\" or http://www.opensolaris.org/os/licensing.
33 .\" See the License for the specific language governing permissions
34 .\" and limitations under the License.
36 .\" When distributing Covered Code, include this CDDL HEADER in each
37 .\" file and include the License file at usr/src/OPENSOLARIS.LICENSE.
38 .\" If applicable, add the following below this CDDL HEADER, with the
39 .\" fields enclosed by brackets "[]" replaced with your own identifying
40 .\" information: Portions Copyright [yyyy] [name of copyright owner]
43 .\" Copyright 1989 AT&T
44 .\" Portions Copyright (c) 1992, X/Open Company Limited. All Rights Reserved.
45 .\" Copyright (c) 2008, Sun Microsystems, Inc. All Rights Reserved.
47 .TH SHM_OPEN 3C "Feb 5, 2008"
49 shm_open \- open a shared memory object
55 \fBint\fR \fBshm_open\fR(\fBconst char *\fR\fIname\fR, \fBint\fR \fIoflag\fR, \fBmode_t\fR \fImode\fR);
61 The \fBshm_open()\fR function establishes a connection between a shared memory
62 object and a file descriptor. It creates an open file description that refers
63 to the shared memory object and a file descriptor that refers to that open file
64 description. The file descriptor is used by other functions to refer to that
65 shared memory object. The \fIname\fR argument points to a string naming a
66 shared memory object. It is unspecified whether the name appears in the file
67 system and is visible to other functions that take pathnames as arguments. The
68 \fIname\fR argument conforms to the construction rules for a pathname. The
69 first character of \fIname\fR must be a slash (/) character and the remaining
70 characters of \fIname\fR cannot include any slash characters. For maximum
71 portability, \fIname\fR should include no more than 14 characters, but this
72 limit is not enforced.
75 If successful, \fBshm_open()\fR returns a file descriptor for the shared memory
76 object that is the lowest numbered file descriptor not currently open for that
77 process. The open file description is new, and therefore the file descriptor
78 does not share it with any other processes. It is unspecified whether the file
79 offset is set. The \fBFD_CLOEXEC\fR file descriptor flag associated with the
80 new file descriptor is set.
83 The file status flags and file access modes of the open file description are
84 according to the value of \fIoflag\fR. The \fIoflag\fR argument is the bitwise
85 inclusive OR of the following flags defined in the header <\fBfcntl.h\fR>.
86 Applications specify exactly one of the first two values (access modes) below
87 in the value of \fIoflag\fR:
94 Open for read access only.
103 Open for read or write access.
108 Any combination of the remaining flags may be specified in the value of
116 If the shared memory object exists, this flag has no effect, except as noted
117 under \fBO_EXCL\fR below. Otherwise the shared memory object is created; the
118 user \fBID\fR of the shared memory object will be set to the effective user
119 \fBID\fR of the process; the group \fBID\fR of the shared memory object will be
120 set to a system default group \fBID\fR or to the effective group \fBID\fR of
121 the process. The permission bits of the shared memory object will be set to the
122 value of the \fImode\fR argument except those set in the file mode creation
123 mask of the process. When bits in \fImode\fR other than the file permission
124 bits are set, the effect is unspecified. The \fImode\fR argument does not
125 affect whether the shared memory object is opened for reading, for writing, or
126 for both. The shared memory object has a size of zero.
135 If \fBO_EXCL\fR and \fBO_CREAT\fR are set, \fBshm_open()\fR fails if the shared
136 memory object exists. The check for the existence of the shared memory object
137 and the creation of the object if it does not exist is atomic with respect to
138 other processes executing \fBshm_open()\fR naming the same shared memory object
139 with \fBO_EXCL\fR and \fBO_CREAT\fR set. If \fBO_EXCL\fR is set and
140 \fBO_CREAT\fR is not set, the result is undefined.
149 If the shared memory object exists, and it is successfully opened \fBO_RDWR\fR,
150 the object will be truncated to zero length and the mode and owner will be
151 unchanged by this function call. The result of using \fBO_TRUNC\fR with
152 \fBO_RDONLY\fR is undefined.
157 When a shared memory object is created, the state of the shared memory object,
158 including all data associated with the shared memory object, persists until the
159 shared memory object is unlinked and all other references are gone. It is
160 unspecified whether the name and shared memory object state remain valid after
165 Upon successful completion, the \fBshm_open()\fR function returns a
166 non-negative integer representing the lowest numbered unused file descriptor.
167 Otherwise, it returns \fB\(mi1\fR and sets \fBerrno\fR to indicate the error
172 The \fBshm_open()\fR function will fail if:
179 The shared memory object exists and the permissions specified by \fIoflag\fR
180 are denied, or the shared memory object does not exist and permission to create
181 the shared memory object is denied, or \fBO_TRUNC\fR is specified and write
182 permission is denied.
191 \fBO_CREAT\fR and \fBO_EXCL\fR are set and the named shared memory object
201 The \fBshm_open()\fR operation was interrupted by a signal.
210 The \fBshm_open()\fR operation is not supported for the given name.
219 Too many file descriptors are currently in use by this process.
225 \fB\fBENAMETOOLONG\fR \fR
228 The length of the \fIname\fR string exceeds \fBPATH_MAX\fR, or a pathname
229 component is longer than \fINAME_MAX\fR while \fB_POSIX_NO_TRUNC\fR is in
239 Too many shared memory objects are currently open in the system.
248 \fBO_CREAT\fR is not set and the named shared memory object does not exist.
257 There is insufficient space for the creation of the new shared memory object.
266 The \fBshm_open()\fR function is not supported by the system.
272 See \fBattributes\fR(5) for descriptions of the following attributes:
280 ATTRIBUTE TYPE ATTRIBUTE VALUE
282 Interface Stability Committed
286 Standard See \fBstandards\fR(5).
292 \fBclose\fR(2), \fBdup\fR(2), \fBexec\fR(2), \fBfcntl\fR(2), \fBmmap\fR(2),
293 \fBumask\fR(2), \fBshm_unlink\fR(3C), \fBsysconf\fR(3C), \fBfcntl.h\fR(3HEAD),
294 \fBattributes\fR(5), \fBstandards\fR(5)
298 Solaris 2.6 was the first release to support the Asynchronous Input and Output
299 option. Prior to this release, this function always returned \fB\(mi1\fR and
300 set \fBerrno\fR to \fBENOSYS\fR.