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