1SHM_OVERVIEW(7) Linux Programmer's Manual SHM_OVERVIEW(7)
2
3
4
6 shm_overview - overview of POSIX shared memory
7
9 The POSIX shared memory API allows processes to communicate information
10 by sharing a region of memory.
11
12 The interfaces employed in the API are:
13
14 shm_open(3) Create and open a new object, or open an existing
15 object. This is analogous to open(2). The call returns
16 a file descriptor for use by the other interfaces listed
17 below.
18
19 ftruncate(2) Set the size of the shared memory object. (A newly cre‐
20 ated shared memory object has a length of zero.)
21
22 mmap(2) Map the shared memory object into the virtual address
23 space of the calling process.
24
25 munmap(2) Unmap the shared memory object from the virtual address
26 space of the calling process.
27
28 shm_unlink(3) Remove a shared memory object name.
29
30 close(2) Close the file descriptor allocated by shm_open(3) when
31 it is no longer needed.
32
33 fstat(2) Obtain a stat structure that describes the shared memory
34 object. Among the information returned by this call are
35 the object's size (st_size), permissions (st_mode),
36 owner (st_uid), and group (st_gid).
37
38 fchown(2) To change the ownership of a shared memory object.
39
40 fchmod(2) To change the permissions of a shared memory object.
41
42 Versions
43 POSIX shared memory is supported since Linux 2.4 and glibc 2.2.
44
45 Persistence
46 POSIX shared memory objects have kernel persistence: a shared memory
47 object will exist until the system is shut down, or until all processes
48 have unmapped the object and it has been deleted with shm_unlink(3)
49
50 Linking
51 Programs using the POSIX shared memory API must be compiled with cc
52 -lrt to link against the real-time library, librt.
53
54 Accessing shared memory objects via the filesystem
55 On Linux, shared memory objects are created in a (tmpfs(5)) virtual
56 filesystem, normally mounted under /dev/shm. Since kernel 2.6.19,
57 Linux supports the use of access control lists (ACLs) to control the
58 permissions of objects in the virtual filesystem.
59
61 Typically, processes must synchronize their access to a shared memory
62 object, using, for example, POSIX semaphores.
63
64 System V shared memory (shmget(2), shmop(2), etc.) is an older shared
65 memory API. POSIX shared memory provides a simpler, and better
66 designed interface; on the other hand POSIX shared memory is somewhat
67 less widely available (especially on older systems) than System V
68 shared memory.
69
71 fchmod(2), fchown(2), fstat(2), ftruncate(2), mmap(2), mprotect(2),
72 munmap(2), shmget(2), shmop(2), shm_open(3), shm_unlink(3), sem_over‐
73 view(7)
74
76 This page is part of release 5.02 of the Linux man-pages project. A
77 description of the project, information about reporting bugs, and the
78 latest version of this page, can be found at
79 https://www.kernel.org/doc/man-pages/.
80
81
82
83Linux 2016-12-12 SHM_OVERVIEW(7)