1 .\" Copyright (c) 1993 Luigi P. Bai (lpb@softint.com) July 28, 1993
3 .\" %%%LICENSE_START(VERBATIM)
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date. The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein. The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
25 .\" Modified Wed Jul 28 10:57:35 1993, Rik Faith <faith@cs.unc.edu>
26 .\" Modified Sun Nov 28 16:43:30 1993, Rik Faith <faith@cs.unc.edu>
27 .\" with material from Giorgio Ciucci <giorgio@crcc.it>
28 .\" Portions Copyright 1993 Giorgio Ciucci <giorgio@crcc.it>
29 .\" Modified Tue Oct 22 22:03:17 1996 by Eric S. Raymond <esr@thyrsus.com>
30 .\" Modified, 8 Jan 2003, Michael Kerrisk, <mtk.manpages@gmail.com>
31 .\" Removed EIDRM from errors - that can't happen...
32 .\" Modified, 27 May 2004, Michael Kerrisk <mtk.manpages@gmail.com>
33 .\" Added notes on capability requirements
34 .\" Modified, 11 Nov 2004, Michael Kerrisk <mtk.manpages@gmail.com>
35 .\" Language and formatting clean-ups
36 .\" Added notes on /proc files
38 .TH SHMGET 2 2015-01-10 "Linux" "Linux Programmer's Manual"
40 shmget \- allocates a System V shared memory segment
43 .B #include <sys/ipc.h>
45 .B #include <sys/shm.h>
47 .BI "int shmget(key_t " key ", size_t " size ", int " shmflg );
51 returns the identifier of the System\ V shared memory segment
52 associated with the value of the argument
54 A new shared memory segment, with size equal to the value of
56 rounded up to a multiple of
66 no shared memory segment corresponding to
79 and a shared memory segment already exists for
87 (This is analogous to the effect of the combination
98 If this flag is not used, then
100 will find the segment associated with \fIkey\fP and check to see if
101 the user has permission to access the segment.
104 This flag is used with
106 to ensure that this call creates the segment.
107 If the segment already exists, the call fails.
109 .BR SHM_HUGETLB " (since Linux 2.6)"
110 Allocate the segment using "huge pages."
111 See the Linux kernel source file
112 .I Documentation/vm/hugetlbpage.txt
113 for further information.
115 .BR SHM_NORESERVE " (since Linux 2.6.15)"
116 This flag serves the same purpose as the
120 Do not reserve swap space for this segment.
121 When swap space is reserved, one has the guarantee
122 that it is possible to modify the segment.
123 When swap space is not reserved one might get
126 if no physical memory is available.
127 See also the discussion of the file
128 .I /proc/sys/vm/overcommit_memory
131 .\" As at 2.6.17-rc2, this flag has no effect if SHM_HUGETLB was also
134 In addition to the above flags, the least significant 9 bits of
136 specify the permissions granted to the owner, group, and others.
137 These bits have the same format, and the same
142 Presently, execute permissions are not used by the system.
144 When a new shared memory segment is created,
145 its contents are initialized to zero values, and
146 its associated data structure,
150 is initialized as follows:
155 are set to the effective user ID of the calling process.
160 are set to the effective group ID of the calling process.
162 The least significant 9 bits of
164 are set to the least significant 9 bit of
168 is set to the value of
179 is set to the current time.
181 If the shared memory segment already exists, the permissions are
182 verified, and a check is made to see if it is marked for destruction.
184 On success, a valid shared memory identifier is returned.
185 On error, \-1 is returned, and
187 is set to indicate the error.
191 is set to one of the following:
194 The user does not have permission to access the
195 shared memory segment, and does not have the
205 but a shared memory segment already exists for
209 A new segment was to be created and
217 A segment for the given
219 exists, but \fIsize\fP is greater than the size
223 .\" [2.6.7] shmem_zero_setup()-->shmem_file_setup()-->get_empty_filp()
224 The system limit on the total number of open files has been reached.
227 No segment exists for the given \fIkey\fP, and
232 No memory could be allocated for segment overhead.
235 All possible shared memory IDs have been taken
237 or allocating a segment of the requested
239 would cause the system to exceed the system-wide limit on shared memory
245 flag was specified, but the caller was not privileged (did not have the
250 .\" SVr4 documents an additional error condition EEXIST.
255 are Linux extensions.
261 isn't required on Linux or by any version of POSIX.
263 some old implementations required the inclusion of these header files,
264 and the SVID also documented their inclusion.
265 Applications intended to be portable to such old systems may need
266 to include these header files.
267 .\" Like Linux, the FreeBSD man pages still document
268 .\" the inclusion of these header files.
271 isn't a flag field but a
274 If this special value is used for
276 the system call ignores all but the least significant 9 bits of
278 and creates a new shared memory segment.
280 .SS Shared memory limits
281 The following limits on shared memory segment resources affect the
286 System-wide limit on the total amount of shared memory,
287 measured in units of the system page size.
289 On Linux, this limit can be read and modified via
290 .IR /proc/sys/kernel/shmall .
292 .\" commit 060028bac94bf60a65415d1d55a359c3a17d5c31
293 the default value for this limit is:
297 The effect of this value
298 (which is suitable for both 32-bit and 64-bit systems)
299 is to impose no limitation on allocations.
300 This value, rather than
302 was chosen as the default to prevent some cases where historical
303 applications simply raised the existing limit without first checking
305 Such applications would cause the value to overflow if the limit was set at
308 From Linux 2.4 up to Linux 3.15,
309 the default value for this limit was:
311 SHMMAX / PAGE_SIZE * (SHMMNI / 16)
317 were not modified, then multiplying the result of this formula
318 by the page size (to get a value in bytes) yielded a value of 8 GB
319 as the limit on the total memory used by all shared memory segments.
322 Maximum size in bytes for a shared memory segment.
324 On Linux, this limit can be read and modified via
325 .IR /proc/sys/kernel/shmmax .
327 .\" commit 060028bac94bf60a65415d1d55a359c3a17d5c31
328 the default value for this limit is:
332 The effect of this value
333 (which is suitable for both 32-bit and 64-bit systems)
334 is to impose no limitation on allocations.
335 See the description of
337 for a discussion of why this default value (rather than
341 From Linux 2.2 up to Linux 3.15, the default value of
342 this limit was 0x2000000 (32MB).
344 Because it is not possible to map just part of a shared memory segment,
345 the amount of virtual memory places another limit on the maximum size of a
347 for example, on i386 the largest segments that can be mapped have a
348 size of around 2.8 GB, and on x86_64 the limit is around 127 TB.
351 Minimum size in bytes for a shared memory segment: implementation
352 dependent (currently 1 byte, though
354 is the effective minimum size).
357 System-wide limit on the number of shared memory segments.
358 In Linux 2.2, the default value for this limit was 128;
359 since Linux 2.4, the default value is 4096.
361 On Linux, this limit can be read and modified via
362 .IR /proc/sys/kernel/shmmni .
363 .\" Kernels between 2.4.x and 2.6.8 had an off-by-one error that meant
364 .\" that we could create one more segment than SHMMNI -- MTK
365 .\" This /proc file is not available in Linux 2.2 and earlier -- MTK
367 The implementation has no specific limits for the per-process maximum
368 number of shared memory segments
371 Until version 2.3.30, Linux would return
375 on a shared memory segment scheduled for deletion.
379 was perhaps unfortunate,
381 would more clearly show its function.
383 .BR memfd_create (2),
388 .BR capabilities (7),
389 .BR shm_overview (7),
392 This page is part of release 3.79 of the Linux
395 A description of the project,
396 information about reporting bugs,
397 and the latest version of this page,
399 \%http://www.kernel.org/doc/man\-pages/.