3 .\" Wilfredo Sanchez, wsanchez@apple.com
4 .\" Copyright (c) 1999 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@
24 .Dd September 20, 1999
29 .Nd open a shared memory object
31 .Fd #include <sys/mman.h>
33 .Fn shm_open "const char *name" "int flags" "mode_t mode"
35 The shared memory object referenced by
37 is opened for reading and/or writing as specified by the argument
39 and the file descriptor returned to the calling process.
40 The returned file descriptor will be the lowest non-open file
41 descriptor for the calling process, and is not shared with any
42 other processes, as it is a new file descriptor. The new file
43 descriptor will have the
49 with the same string value for
51 will return a file descriptor referring to the same shared memory
52 object, provided that the object has not been unlinked by a call to
56 argument may indicate the file is to be
57 created if it does not exist (by specifying the
59 flag), in which case the file is created with mode
63 and modified by the process' umask value (see
66 The flags specified are formed by
70 .Bd -literal -offset indent -compact
71 O_RDONLY open for reading only
72 O_RDWR open for reading and writing
73 O_CREAT create object if it does not exist
74 O_EXCL error if create and object exists
75 O_TRUNC truncate size to 0
87 file exists, the file is truncated to zero length.
95 returns an error. This may be used to
96 implement a simple exclusive access locking mechanism.
100 returns a non-negative integer, termed a file descriptor.
101 It returns -1 and sets
104 The file pointer used to mark the current position within the
105 memory object is set to the beginning of the object.
107 When a new shared memory object is created it is given the
108 owner and group corresponding to the effective user and
109 group of the calling process. There is no visible entry in the
110 file system for the created object in this implementation.
112 When a shared memory object is created, it persists until it
113 it unlinked and all other references are gone. Objects do
114 not persist across a system reboot.
116 The new descriptor is set to remain open across
123 The system imposes a limit on the number of file descriptors
124 open simultaneously by one process.
126 returns the current system limit.
128 The named object is opened unless:
131 The required permissions (for reading and/or writing)
132 are denied for the given flags.
135 is specified, the object does not exist, and permission to
136 create the object is denied.
141 were specified and the object exists.
145 operation was interrupted by a signal.
149 operation is not supported.
151 The process has already reached its limit for open file descriptors.
152 .It Bq Er ENAMETOOLONG
158 The system file table is full.
161 is not set and the named object does not exist.
164 is specified, the file does not exist, and there is insufficient
165 space available to create the object.
170 .Xr getdtablesize 2 ,
176 is specified in the POSIX Realtime Extension (1003.1b-1993/1003.1i-1995).