3 .\" Copyright (c) 1999-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@
23 .Dd September 20, 1999
28 .Nd open a shared memory object
30 .Fd #include <sys/mman.h>
32 .Fn shm_open "const char *name" "int flags" "mode_t mode"
34 The shared memory object referenced by
36 is opened for reading and/or writing as specified by the argument
38 and the file descriptor returned to the calling process.
39 The returned file descriptor will be the lowest non-open file
40 descriptor for the calling process, and is not shared with any
41 other processes, as it is a new file descriptor. The new file
42 descriptor will have the
48 with the same string value for
50 will return a file descriptor referring to the same shared memory
51 object, provided that the object has not been unlinked by a call to
55 argument may indicate the file is to be
56 created if it does not exist (by specifying the
58 flag), in which case the file is created with mode
62 and modified by the process' umask value (see
65 The flags specified are formed by
69 .Bd -literal -offset indent -compact
70 O_RDONLY open for reading only
71 O_RDWR open for reading and writing
72 O_CREAT create object if it does not exist
73 O_EXCL error if create and object exists
74 O_TRUNC truncate size to 0
86 file exists, the file is truncated to zero length.
94 returns an error. This may be used to
95 implement a simple exclusive access locking mechanism.
99 returns a non-negative integer, termed a file descriptor.
100 It returns -1 and sets
103 The file pointer used to mark the current position within the
104 memory object is set to the beginning of the object.
106 When a new shared memory object is created it is given the
107 owner and group corresponding to the effective user and
108 group of the calling process. There is no visible entry in the
109 file system for the created object in this implementation.
111 When a shared memory object is created, it persists until it
112 it unlinked and all other references are gone. Objects do
113 not persist across a system reboot.
115 The new descriptor is set to remain open across
122 The system imposes a limit on the number of file descriptors
123 open simultaneously by one process.
125 returns the current system limit.
127 The named object is opened unless:
130 The required permissions (for reading and/or writing)
131 are denied for the given flags.
134 is specified, the object does not exist, and permission to
135 create the object is denied.
140 were specified and the object exists.
144 operation was interrupted by a signal.
148 operation is not supported.
150 The process has already reached its limit for open file descriptors.
151 .It Bq Er ENAMETOOLONG
157 The system file table is full.
160 is not set and the named object does not exist.
163 is specified, the file does not exist, and there is insufficient
164 space available to create the object.
169 .Xr getdtablesize 2 ,
175 is specified in the POSIX Realtime Extension (1003.1b-1993/1003.1i-1995).