termios.3: wfix
[man-pages.git] / man7 / shm_overview.7
blob60e7b71d33308862533f032945959ce9151837ba
1 .\" Copyright (C) 2008, Linux Foundation, written by Michael Kerrisk
2 .\" <mtk.manpages@gmail.com>
3 .\"
4 .\" %%%LICENSE_START(VERBATIM)
5 .\" Permission is granted to make and distribute verbatim copies of this
6 .\" manual provided the copyright notice and this permission notice are
7 .\" preserved on all copies.
8 .\"
9 .\" Permission is granted to copy and distribute modified versions of this
10 .\" manual under the conditions for verbatim copying, provided that the
11 .\" entire resulting derived work is distributed under the terms of a
12 .\" permission notice identical to this one.
13 .\"
14 .\" Since the Linux kernel and libraries are constantly changing, this
15 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
16 .\" responsibility for errors or omissions, or for damages resulting from
17 .\" the use of the information contained herein.  The author(s) may not
18 .\" have taken the same level of care in the production of this manual,
19 .\" which is licensed free of charge, as they might when working
20 .\" professionally.
21 .\"
22 .\" Formatted or processed versions of this manual, if unaccompanied by
23 .\" the source, must acknowledge the copyright and authors of this work.
24 .\" %%%LICENSE_END
25 .\"
26 .TH SHM_OVERVIEW 7 2021-03-22 "Linux" "Linux Programmer's Manual"
27 .SH NAME
28 shm_overview \- overview of POSIX shared memory
29 .SH DESCRIPTION
30 The POSIX shared memory API allows processes to communicate information
31 by sharing a region of memory.
32 .PP
33 The interfaces employed in the API are:
34 .TP 15
35 .BR shm_open (3)
36 Create and open a new object, or open an existing object.
37 This is analogous to
38 .BR open (2).
39 The call returns a file descriptor for use by the other
40 interfaces listed below.
41 .TP
42 .BR ftruncate (2)
43 Set the size of the shared memory object.
44 (A newly created shared memory object has a length of zero.)
45 .TP
46 .BR mmap (2)
47 Map the shared memory object into the virtual address space
48 of the calling process.
49 .TP
50 .BR munmap (2)
51 Unmap the shared memory object from the virtual address space
52 of the calling process.
53 .TP
54 .BR shm_unlink (3)
55 Remove a shared memory object name.
56 .TP
57 .BR close (2)
58 Close the file descriptor allocated by
59 .BR shm_open (3)
60 when it is no longer needed.
61 .TP
62 .BR fstat (2)
63 Obtain a
64 .I stat
65 structure that describes the shared memory object.
66 Among the information returned by this call are the object's
67 size
68 .RI ( st_size ),
69 permissions
70 .RI ( st_mode ),
71 owner
72 .RI ( st_uid ),
73 and group
74 .RI ( st_gid ).
75 .TP
76 .BR fchown (2)
77 To change the ownership of a shared memory object.
78 .TP
79 .BR fchmod (2)
80 To change the permissions of a shared memory object.
81 .SS Versions
82 POSIX shared memory is supported since Linux 2.4 and glibc 2.2.
83 .SS Persistence
84 POSIX shared memory objects have kernel persistence:
85 a shared memory object will exist until the system is shut down,
86 or until all processes have unmapped the object and it has been deleted with
87 .BR shm_unlink (3)
88 .SS Linking
89 Programs using the POSIX shared memory API must be compiled with
90 .I cc \-lrt
91 to link against the real-time library,
92 .IR librt .
93 .SS Accessing shared memory objects via the filesystem
94 On Linux, shared memory objects are created in a
95 .RB ( tmpfs (5))
96 virtual filesystem, normally mounted under
97 .IR /dev/shm .
98 Since kernel 2.6.19, Linux supports the use of access control lists (ACLs)
99 to control the permissions of objects in the virtual filesystem.
100 .SH NOTES
101 Typically, processes must synchronize their access to a shared
102 memory object, using, for example, POSIX semaphores.
104 System V shared memory
105 .RB ( shmget (2),
106 .BR shmop (2),
107 etc.) is an older shared memory API.
108 POSIX shared memory provides a simpler, and better designed interface;
109 on the other hand POSIX shared memory is somewhat less widely available
110 (especially on older systems) than System V shared memory.
111 .SH SEE ALSO
112 .BR fchmod (2),
113 .BR fchown (2),
114 .BR fstat (2),
115 .BR ftruncate (2),
116 .BR memfd_create (2),
117 .BR mmap (2),
118 .BR mprotect (2),
119 .BR munmap (2),
120 .BR shmget (2),
121 .BR shmop (2),
122 .BR shm_open (3),
123 .BR shm_unlink (3),
124 .BR sem_overview (7)