Debian Codegraph @

upstream/debian-unstable/man7/shm_overview.7

raw
1 .\" Copyright, the authors of the Linux man-pages project
2 .\"
3 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
4 .\"
5 .TH shm_overview 7 2025-05-17 "Linux man-pages 6.18"
6 .SH NAME
7 shm_overview \- overview of POSIX shared memory
8 .SH DESCRIPTION
9 The POSIX shared memory API allows processes to communicate information
10 by sharing a region of memory.
11 .P
12 The interfaces employed in the API are:
13 .TP 15
14 .BR shm_open (3)
15 Create and open a new object, or open an existing object.
16 This is analogous to
17 .BR open (2).
18 The call returns a file descriptor for use by the other
19 interfaces listed below.
20 .TP
21 .BR ftruncate (2)
22 Set the size of the shared memory object.
23 (A newly created shared memory object has a length of zero.)
24 .TP
25 .BR mmap (2)
26 Map the shared memory object into the virtual address space
27 of the calling process.
28 .TP
29 .BR munmap (2)
30 Unmap the shared memory object from the virtual address space
31 of the calling process.
32 .TP
33 .BR shm_unlink (3)
34 Remove a shared memory object name.
35 .TP
36 .BR close (2)
37 Close the file descriptor allocated by
38 .BR shm_open (3)
39 when it is no longer needed.
40 .TP
41 .BR fstat (2)
42 Obtain a
43 .I stat
44 structure that describes the shared memory object.
45 Among the information returned by this call are the object's
46 size
47 .RI ( st_size ),
48 permissions
49 .RI ( st_mode ),
50 owner
51 .RI ( st_uid ),
52 and group
53 .RI ( st_gid ).
54 .TP
55 .BR fchown (2)
56 To change the ownership of a shared memory object.
57 .TP
58 .BR fchmod (2)
59 To change the permissions of a shared memory object.
60 .SS Versions
61 POSIX shared memory is supported since Linux 2.4 and glibc 2.2.
62 .SS Persistence
63 POSIX shared memory objects have kernel persistence:
64 a shared memory object will exist until the system is shut down,
65 or until all processes have unmapped the object and it has been deleted with
66 .BR shm_unlink (3)
67 .SS Linking
68 Programs using the POSIX shared memory API must be compiled with
69 .I cc \-lrt
70 to link against the real-time library,
71 .IR librt .
72 .SS Accessing shared memory objects via the filesystem
73 On Linux, shared memory objects are created in a
74 .RB ( tmpfs (5))
75 virtual filesystem, normally mounted under
76 .IR /dev/shm .
77 Since Linux 2.6.19, Linux supports the use of access control lists (ACLs)
78 to control the permissions of objects in the virtual filesystem.
79 .SH NOTES
80 Typically, processes must synchronize their access to a shared
81 memory object, using, for example, POSIX semaphores.
82 .P
83 System V shared memory
84 .RB ( shmget (2),
85 .BR shmop (2),
86 etc.) is an older shared memory API.
87 POSIX shared memory provides a simpler, and better designed interface;
88 on the other hand POSIX shared memory is somewhat less widely available
89 (especially on older systems) than System V shared memory.
90 .SH SEE ALSO
91 .BR fchmod (2),
92 .BR fchown (2),
93 .BR fstat (2),
94 .BR ftruncate (2),
95 .BR memfd_create (2),
96 .BR mmap (2),
97 .BR mprotect (2),
98 .BR munmap (2),
99 .BR shmget (2),
100 .BR shmop (2),
101 .BR shm_open (3),
102 .BR shm_unlink (3),
103 .BR sem_overview (7)