man-pages/man7/shm_overview.7.html
2021-03-31 01:06:50 +01:00

197 lines
5.6 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML><HEAD><TITLE>Man page of SHM_OVERVIEW</TITLE>
</HEAD><BODY>
<H1>SHM_OVERVIEW</H1>
Section: Linux Programmer's Manual (7)<BR>Updated: 2016-12-12<BR><A HREF="#index">Index</A>
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
<A NAME="lbAB">&nbsp;</A>
<H2>NAME</H2>
shm_overview - overview of POSIX shared memory
<A NAME="lbAC">&nbsp;</A>
<H2>DESCRIPTION</H2>
The POSIX shared memory API allows processes to communicate information
by sharing a region of memory.
<P>
The interfaces employed in the API are:
<DL COMPACT>
<DT id="1"><B><A HREF="/cgi-bin/man/man2html?3+shm_open">shm_open</A></B>(3)
<DD>
Create and open a new object, or open an existing object.
This is analogous to
<B><A HREF="/cgi-bin/man/man2html?2+open">open</A></B>(2).
The call returns a file descriptor for use by the other
interfaces listed below.
<DT id="2"><B><A HREF="/cgi-bin/man/man2html?2+ftruncate">ftruncate</A></B>(2)
<DD>
Set the size of the shared memory object.
(A newly created shared memory object has a length of zero.)
<DT id="3"><B><A HREF="/cgi-bin/man/man2html?2+mmap">mmap</A></B>(2)
<DD>
Map the shared memory object into the virtual address space
of the calling process.
<DT id="4"><B><A HREF="/cgi-bin/man/man2html?2+munmap">munmap</A></B>(2)
<DD>
Unmap the shared memory object from the virtual address space
of the calling process.
<DT id="5"><B><A HREF="/cgi-bin/man/man2html?3+shm_unlink">shm_unlink</A></B>(3)
<DD>
Remove a shared memory object name.
<DT id="6"><B><A HREF="/cgi-bin/man/man2html?2+close">close</A></B>(2)
<DD>
Close the file descriptor allocated by
<B><A HREF="/cgi-bin/man/man2html?3+shm_open">shm_open</A></B>(3)
when it is no longer needed.
<DT id="7"><B><A HREF="/cgi-bin/man/man2html?2+fstat">fstat</A></B>(2)
<DD>
Obtain a
<I>stat</I>
structure that describes the shared memory object.
Among the information returned by this call are the object's
size
(<I>st_size</I>),
permissions
(<I>st_mode</I>),
owner
(<I>st_uid</I>),
and group
(<I>st_gid</I>).
<DT id="8"><B><A HREF="/cgi-bin/man/man2html?2+fchown">fchown</A></B>(2)
<DD>
To change the ownership of a shared memory object.
<DT id="9"><B><A HREF="/cgi-bin/man/man2html?2+fchmod">fchmod</A></B>(2)
<DD>
To change the permissions of a shared memory object.
</DL>
<A NAME="lbAD">&nbsp;</A>
<H3>Versions</H3>
POSIX shared memory is supported since Linux 2.4 and glibc 2.2.
<A NAME="lbAE">&nbsp;</A>
<H3>Persistence</H3>
POSIX shared memory objects have kernel persistence:
a shared memory object will exist until the system is shut down,
or until all processes have unmapped the object and it has been deleted with
<B><A HREF="/cgi-bin/man/man2html?3+shm_unlink">shm_unlink</A></B>(3)
<A NAME="lbAF">&nbsp;</A>
<H3>Linking</H3>
Programs using the POSIX shared memory API must be compiled with
<I>cc -lrt</I>
to link against the real-time library,
<I>librt</I>.
<A NAME="lbAG">&nbsp;</A>
<H3>Accessing shared memory objects via the filesystem</H3>
On Linux, shared memory objects are created in a
(<I><A HREF="/cgi-bin/man/man2html?5+tmpfs">tmpfs</A></I>(5))
virtual filesystem, normally mounted under
<I>/dev/shm</I>.
Since kernel 2.6.19, Linux supports the use of access control lists (ACLs)
to control the permissions of objects in the virtual filesystem.
<A NAME="lbAH">&nbsp;</A>
<H2>NOTES</H2>
Typically, processes must synchronize their access to a shared
memory object, using, for example, POSIX semaphores.
<P>
System V shared memory
(<B><A HREF="/cgi-bin/man/man2html?2+shmget">shmget</A></B>(2),
<B><A HREF="/cgi-bin/man/man2html?2+shmop">shmop</A></B>(2),
etc.) is an older shared memory API.
POSIX shared memory provides a simpler, and better designed interface;
on the other hand POSIX shared memory is somewhat less widely available
(especially on older systems) than System V shared memory.
<A NAME="lbAI">&nbsp;</A>
<H2>SEE ALSO</H2>
<B><A HREF="/cgi-bin/man/man2html?2+fchmod">fchmod</A></B>(2),
<B><A HREF="/cgi-bin/man/man2html?2+fchown">fchown</A></B>(2),
<B><A HREF="/cgi-bin/man/man2html?2+fstat">fstat</A></B>(2),
<B><A HREF="/cgi-bin/man/man2html?2+ftruncate">ftruncate</A></B>(2),
<B><A HREF="/cgi-bin/man/man2html?2+mmap">mmap</A></B>(2),
<B><A HREF="/cgi-bin/man/man2html?2+mprotect">mprotect</A></B>(2),
<B><A HREF="/cgi-bin/man/man2html?2+munmap">munmap</A></B>(2),
<B><A HREF="/cgi-bin/man/man2html?2+shmget">shmget</A></B>(2),
<B><A HREF="/cgi-bin/man/man2html?2+shmop">shmop</A></B>(2),
<B><A HREF="/cgi-bin/man/man2html?3+shm_open">shm_open</A></B>(3),
<B><A HREF="/cgi-bin/man/man2html?3+shm_unlink">shm_unlink</A></B>(3),
<B><A HREF="/cgi-bin/man/man2html?7+sem_overview">sem_overview</A></B>(7)
<A NAME="lbAJ">&nbsp;</A>
<H2>COLOPHON</H2>
This page is part of release 5.05 of the Linux
<I>man-pages</I>
project.
A description of the project,
information about reporting bugs,
and the latest version of this page,
can be found at
<A HREF="https://www.kernel.org/doc/man-pages/.">https://www.kernel.org/doc/man-pages/.</A>
<P>
<HR>
<A NAME="index">&nbsp;</A><H2>Index</H2>
<DL>
<DT id="10"><A HREF="#lbAB">NAME</A><DD>
<DT id="11"><A HREF="#lbAC">DESCRIPTION</A><DD>
<DL>
<DT id="12"><A HREF="#lbAD">Versions</A><DD>
<DT id="13"><A HREF="#lbAE">Persistence</A><DD>
<DT id="14"><A HREF="#lbAF">Linking</A><DD>
<DT id="15"><A HREF="#lbAG">Accessing shared memory objects via the filesystem</A><DD>
</DL>
<DT id="16"><A HREF="#lbAH">NOTES</A><DD>
<DT id="17"><A HREF="#lbAI">SEE ALSO</A><DD>
<DT id="18"><A HREF="#lbAJ">COLOPHON</A><DD>
</DL>
<HR>
This document was created by
<A HREF="/cgi-bin/man/man2html">man2html</A>,
using the manual pages.<BR>
Time: 00:06:09 GMT, March 31, 2021
</BODY>
</HTML>