1shm_open(3C)             Standard C Library Functions             shm_open(3C)
2
3
4

NAME

6       shm_open - open a shared memory object
7

SYNOPSIS

9       #include <sys/mman.h>
10
11       int shm_open(const char *name, int oflag, mode_t mode);
12
13

DESCRIPTION

15       The  shm_open() function establishes a connection between a shared mem‐
16       ory object and a file descriptor. It creates an open  file  description
17       that  refers  to  the  shared  memory object and a file descriptor that
18       refers to that open file description. The file descriptor  is  used  by
19       other  functions  to refer to that shared memory object. The name argu‐
20       ment points to a string naming a shared memory object. It  is  unspeci‐
21       fied  whether  the  name  appears  in the file system and is visible to
22       other functions that take pathnames as  arguments.  The  name  argument
23       conforms  to the construction rules for a pathname. The first character
24       of  name must be a slash  (/) character and the remaining characters of
25       name  cannot  include  any  slash characters.  For maximum portability,
26       name should include no more than 14 characters, but this limit  is  not
27       enforced.
28
29
30       If successful, shm_open() returns a file descriptor for the shared mem‐
31       ory object that is the lowest numbered file  descriptor  not  currently
32       open  for that process. The open file description is new, and therefore
33       the file descriptor does not share it with any other processes.  It  is
34       unspecified  whether  the  file  offset  is  set.  The  FD_CLOEXEC file
35       descriptor flag associated with the new file descriptor is set.
36
37
38       The file status flags and file access modes of the open  file  descrip‐
39       tion  are  according  to  the value of oflag. The oflag argument is the
40       bitwise inclusive OR of the  following  flags  defined  in  the  header
41       <fcntl.h>.  Applications  specify  exactly  one of the first two values
42       (access modes) below in the value of oflag:
43
44       O_RDONLY     Open for read access only.
45
46
47       O_RDWR       Open for read or write access.
48
49
50
51       Any combination of the remaining flags may be specified in the value of
52       oflag:
53
54       O_CREAT     If  the  shared  memory  object  exists,  this  flag has no
55                   effect, except as noted under O_EXCL below.  Otherwise  the
56                   shared  memory object is created; the user ID of the shared
57                   memory object will be set to the effective user ID  of  the
58                   process;  the  group ID of the shared memory object will be
59                   set to a system default group ID or to the effective  group
60                   ID of the process. The permission bits of the shared memory
61                   object will be set to the value of the mode argument except
62                   those  set  in  the file mode creation mask of the process.
63                   When bits in mode other than the file permission  bits  are
64                   set,  the effect is unspecified. The mode argument does not
65                   affect whether the shared memory object is opened for read‐
66                   ing, for writing, or for both. The shared memory object has
67                   a size of zero.
68
69
70       O_EXCL      If O_EXCL and O_CREAT are  set,  shm_open()  fails  if  the
71                   shared memory object exists. The check for the existence of
72                   the shared memory object and the creation of the object  if
73                   it does not exist is atomic with respect to other processes
74                   executing shm_open() naming the same shared  memory  object
75                   with  O_EXCL  and O_CREAT set. If O_EXCL is set and O_CREAT
76                   is not set, the result is undefined.
77
78
79       O_TRUNC     If the shared memory object exists, and it is  successfully
80                   opened  O_RDWR, the object will be truncated to zero length
81                   and the mode and owner will be unchanged by  this  function
82                   call.  The  result  of using O_TRUNC with O_RDONLY is unde‐
83                   fined.
84
85
86
87       When a shared memory object is created, the state of the shared  memory
88       object,  including  all  data associated with the shared memory object,
89       persists until the shared memory object is unlinked and all other  ref‐
90       erences  are gone. It is unspecified whether the name and shared memory
91       object state remain valid after a system reboot.
92

RETURN VALUES

94       Upon successful completion, the shm_open() function returns a non-nega‐
95       tive  integer  representing the lowest numbered unused file descriptor.
96       Otherwise, it returns −1 and sets errno to indicate  the  error  condi‐
97       tion.
98

ERRORS

100       The shm_open() function will fail if:
101
102       EACCES           The  shared  memory  object exists and the permissions
103                        specified by oflag are denied, or  the  shared  memory
104                        object  does  not  exist  and permission to create the
105                        shared memory object is denied, or O_TRUNC  is  speci‐
106                        fied and write permission is denied.
107
108
109       EEXIST           O_CREAT and O_EXCL are set and the named shared memory
110                        object already exists.
111
112
113       EINTR            The shm_open() operation was interrupted by a signal.
114
115
116       EINVAL           The shm_open() operation  is  not  supported  for  the
117                        given name.
118
119
120       EMFILE           Too many file descriptors are currently in use by this
121                        process.
122
123
124       ENAMETOOLONG     The length of the name string exceeds PATH_MAX,  or  a
125                        pathname  component  is  longer  than  NAME_MAX  while
126                        _POSIX_NO_TRUNC is in effect.
127
128
129       ENFILE           Too many shared memory objects are currently  open  in
130                        the system.
131
132
133       ENOENT           O_CREAT  is not set and the named shared memory object
134                        does not exist.
135
136
137       ENOSPC           There is insufficient space for the  creation  of  the
138                        new shared memory object.
139
140
141       ENOSYS           The  shm_open()  function is not supported by the sys‐
142                        tem.
143
144

ATTRIBUTES

146       See attributes(5) for descriptions of the following attributes:
147
148
149
150
151       ┌─────────────────────────────┬─────────────────────────────┐
152ATTRIBUTE TYPE               ATTRIBUTE VALUE              
153       ├─────────────────────────────┼─────────────────────────────┤
154       │Interface Stability          │Committed                    │
155       ├─────────────────────────────┼─────────────────────────────┤
156       │MT-Level                     │MT-Safe                      │
157       ├─────────────────────────────┼─────────────────────────────┤
158       │Standard                     │See standards(5).            │
159       └─────────────────────────────┴─────────────────────────────┘
160

SEE ALSO

162       close(2), dup(2), exec(2), fcntl(2), mmap(2), umask(2), shm_unlink(3C),
163       sysconf(3C), fcntl.h(3HEAD), attributes(5), standards(5)
164

NOTES

166       Solaris 2.6 was the first release to support the Asynchronous Input and
167       Output option. Prior to this release, this function always returned  −1
168       and set errno to ENOSYS.
169
170
171
172SunOS 5.11                        5 Feb 2008                      shm_open(3C)
Impressum