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