Penguin
Annotated edit history of shmget(2) version 2, including all changes. View license author blame.
Rev Author # Line
1 perry 1 SHMGET
2 !!!SHMGET
3 NAME
4 SYNOPSIS
5 DESCRIPTION
6 SYSTEM CALLS
7 RETURN VALUE
8 ERRORS
9 NOTES
10 BUGS
11 CONFORMING TO
12 SEE ALSO
13 ----
14 !!NAME
15
16
17 shmget - allocates a shared memory segment
18 !!SYNOPSIS
19
20
21 __#include __
22
23
24 __#include __
25
26
27 __int shmget(key_t__ ''key''__, int__
28 ''size''__, int__ ''shmflg''__);__
29 !!DESCRIPTION
30
31
32 __shmget()__ returns the identifier of the shared memory
33 segment associated to the value of the argument ''key''.
34 A new shared memory segment, with size equal to the round up
35 of ''size'' to a multiple of __PAGE_SIZE__, is created
36 if ''key'' has value __IPC_PRIVATE__ or ''key''
37 isn't __IPC_PRIVATE__, no shared memory segment is
38 associated to ''key'', and __IPC_CREAT__ is asserted
39 in ''shmflg'' (i.e. ''shmflg''____
40 isn't zero). The presence in
41
42
43 ''shmflg'' is composed of:
44
45
46 __IPC_CREAT__
47
48
49 to create a new segment. If this flag is not used, then
50 __shmget()__ will find the segment associated with
51 ''key'', check to see if the user has permission to
52 receive the ''shmid'' associated with the segment, and
53 ensure the segment is not marked for
54 destruction.
55
56
57 __IPC_EXCL__
58
59
60 used with __IPC_CREAT__ to ensure failure if the segment
61 exists.
62
63
64 __mode_flags (lowest 9 bits)__
65
66
67 specifying the permissions granted to the owner, group, and
68 world. Presently, the execute permissions are not used by
69 the system.
70
71
72 If a new segment is created, the access permissions from
73 ''shmflg'' are copied into the ''shm_perm'' member of
74 the ''shmid_ds'' structure that defines the segment. The
75 ''shmid_ds'' structure:
76
77
78 struct shmid_ds {
79 struct ipc_perm shm_perm; /* operation perms */
80 int shm_segsz; /* size of segment (bytes) */
81 time_t shm_atime; /* last attach time */
82 time_t shm_dtime; /* last detach time */
83 time_t shm_ctime; /* last change time */
84 unsigned short shm_cpid; /* pid of creator */
85 unsigned short shm_lpid; /* pid of last operator */
86 short shm_nattch; /* no. of current attaches */
87 };
88
89
90 struct ipc_perm {
91 key_t key;
92 ushort uid; /* owner euid and egid */
93 ushort gid;
94 ushort cuid; /* creator euid and egid */
95 ushort cgid;
96 ushort mode; /* lower 9 bits of ''shmflg'' */
97 ushort seq; /* sequence number */
98 };
99
100
101 Furthermore, while creating, the system call initializes the
102 system shared memory segment data structure __shmid_ds__
103 as follows:
104
105
106 __shm_perm.cuid__ and __shm_perm.uid__ are set to the
107 effective user-ID of the calling process.
108
109
110 __shm_perm.cgid__ and __shm_perm.gid__ are set to the
111 effective group-ID of the calling process.
112
113
114 The lowest order 9 bits of __shm_perm.mode__ are set to
115 the lowest order 9 bit of ''shmflg''.
116
117
118 __shm_segsz__ is set to the value of
119 ''size.''
120
121
122 __shm_lpid__, __shm_nattch__, __shm_atime__ and
123 __shm_dtime__ are set to __0.__
124
125
126 __shm_ctime__ is set to the current time.
127
128
129 If the shared memory segment already exists, the access
130 permissions are verified, and a check is made to see if it
131 is marked for destruction.
132 !!SYSTEM CALLS
133
134
135 __fork()__
136
137
138 After a __fork()__ the child inherits the attached shared
139 memory segments.
140
141
142 __exec()__
143
144
145 After an __exec()__ all attached shared memory segments
146 are detached (not destroyed).
147
148
149 __exit()__
150
151
152 Upon __exit()__ all attached shared memory segments are
153 detached (not destroyed).
154 !!RETURN VALUE
155
156
157 A valid segment identifier, ''shmid'', is returned on
158 success, -1 on error.
159 !!ERRORS
160
161
162 On failure, __errno__ is set to one of the
163 following:
164
165
166 __EINVAL__
167
168
169 is returned if a new segment was to be created and
170 ''size'' ''SHMMIN__ or ''size''
171 ''SHMMAX__, or no new segment was to be created, a
172 segment with given key existed, but ''size'' is greater
2 RuudSchramp 173 than the size of that segment (On Fedora core this condition results in ESPIPE! Illegal Seek).
1 perry 174
175
176 __EEXIST__
177
178
179 is returned if __IPC_CREAT | IPC_EXCL__ was specified and
180 the segment exists.
181
182
183 __EIDRM__
184
185
186 is returned if the segment is marked as destroyed, or was
187 removed.
188
189
190 __ENOSPC__
191
192
193 is returned if all possible shared memory id's have been
194 taken (__SHMMNI__) or if allocating a segment of the
195 requested ''size'' would cause the system to exceed the
196 system-wide limit on shared memory
197 (__SHMALL__).
198
199
200 __ENOENT__
201
202
203 is returned if no segment exists for the given ''key'',
204 and __IPC_CREAT__ was not specified.
205
206
207 __EACCES__
208
209
210 is returned if the user does not have permission to access
211 the shared memory segment.
212
213
214 __ENOMEM__
215
216
217 is returned if no memory could be allocated for segment
218 overhead.
219 !!NOTES
220
221
222 __IPC_PRIVATE__ isn't a flag field but a __key_t__
223 type. If this special value is used for ''key'', the
224 system call ignores everything but the lowest order 9 bits
225 of ''shmflg'' and creates a new shared memory segment (on
226 success).
227
228
229 The followings are limits on shared memory segment resources
230 affecting a __shmget__ call:
231
232
233 __SHMALL__
234
235
236 System wide maximum of shared memory pages: policy
237 dependent.
238
239
240 __SHMMAX__
241
242
243 Maximum size in bytes for a shared memory segment:
244 implementation dependent (currently 4M).
245
246
247 __SHMMIN__
248
249
250 Minimum size in bytes for a shared memory segment:
251 implementation dependent (currently 1 byte, though
252 __PAGE_SIZE__ is the effective minimum
253 size).
254
255
256 __SHMMNI__
257
258
259 System wide maximum number of shared memory segments:
260 implementation dependent (currently 4096, was 128 in Linux
261 2.2 kernels).
262
263
264 The implementation has no specific limits for the per
265 process maximum number of shared memory segments
266 (__SHMSEG__).
267 !!BUGS
268
269
270 Use of __IPC_PRIVATE__ doesn't inhibit to other processes
271 the access to the allocated shared memory
272 segment.
273
274
275 As for the files, there is currently no intrinsic way for a
276 process to ensure exclusive access to a shared memory
277 segment. Asserting both __IPC_CREAT__ and __IPC_EXCL__
278 in ''shmflg'' only ensures (on success) that a new shared
279 memory segment will be created, it doesn't imply exclusive
280 access to the segment.
281 !!CONFORMING TO
282
283
284 SVr4, SVID. SVr4 documents an additional error condition
285 EEXIST. Neither SVr4 nor SVID documents an EIDRM
286 condition.
287 !!SEE ALSO
288
289
290 ftok(3), ipc(5), shmctl(2),
291 shmat(2), shmdt(2)
292 ----
This page is a man page (or other imported legacy content). We are unable to automatically determine the license status of this page.