{"id":3934,"date":"2022-12-20T17:28:27","date_gmt":"2022-12-20T20:28:27","guid":{"rendered":"http:\/\/lode.uno\/linux-man\/index.php\/2022\/12\/20\/shm_overview-man7\/"},"modified":"2022-12-20T17:28:27","modified_gmt":"2022-12-20T20:28:27","slug":"shm_overview-man7","status":"publish","type":"post","link":"https:\/\/lode.uno\/linux-man\/2022\/12\/20\/shm_overview-man7\/","title":{"rendered":"SHM_OVERVIEW (man7)"},"content":{"rendered":"<h1 align=\"center\">SHM_OVERVIEW<\/h1>\n<p> <a href=\"#NAME\">NAME<\/a><br \/> <a href=\"#DESCRIPTION\">DESCRIPTION<\/a><br \/> <a href=\"#NOTES\">NOTES<\/a><br \/> <a href=\"#SEE ALSO\">SEE ALSO<\/a><br \/> <a href=\"#COLOPHON\">COLOPHON<\/a> <\/p>\n<hr>\n<h2>NAME <a name=\"NAME\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">shm_overview \u2212 overview of POSIX shared memory<\/p>\n<h2>DESCRIPTION <a name=\"DESCRIPTION\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">The POSIX shared memory API allows processes to communicate information by sharing a region of memory.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The interfaces employed in the API are:<\/p>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"20%\">\n<p><b>shm_open<\/b>(3)<\/p>\n<\/td>\n<td width=\"3%\"><\/td>\n<td width=\"66%\">\n<p>Create and open a new object, or open an existing object. This is analogous to <b>open<\/b>(2). The call returns a file descriptor for use by the other interfaces listed below.<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"20%\">\n<p><b>ftruncate<\/b>(2)<\/p>\n<\/td>\n<td width=\"3%\"><\/td>\n<td width=\"66%\">\n<p>Set the size of the shared memory object. (A newly created shared memory object has a length of zero.)<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"20%\">\n<p><b>mmap<\/b>(2)<\/p>\n<\/td>\n<td width=\"3%\"><\/td>\n<td width=\"66%\">\n<p>Map the shared memory object into the virtual address space of the calling process.<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"20%\">\n<p><b>munmap<\/b>(2)<\/p>\n<\/td>\n<td width=\"3%\"><\/td>\n<td width=\"66%\">\n<p>Unmap the shared memory object from the virtual address space of the calling process.<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"20%\">\n<p><b>shm_unlink<\/b>(3)<\/p>\n<\/td>\n<td width=\"3%\"><\/td>\n<td width=\"66%\">\n<p>Remove a shared memory object name.<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"20%\">\n<p><b>close<\/b>(2)<\/p>\n<\/td>\n<td width=\"3%\"><\/td>\n<td width=\"66%\">\n<p>Close the file descriptor allocated by <b>shm_open<\/b>(3) when it is no longer needed.<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"20%\">\n<p><b>fstat<\/b>(2)<\/p>\n<\/td>\n<td width=\"3%\"><\/td>\n<td width=\"66%\">\n<p>Obtain a <i>stat<\/i> structure that describes the shared memory object. Among the information returned by this call are the object\u2019s size (<i>st_size<\/i>), permissions (<i>st_mode<\/i>), owner (<i>st_uid<\/i>), and group (<i>st_gid<\/i>).<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"20%\">\n<p><b>fchown<\/b>(2)<\/p>\n<\/td>\n<td width=\"3%\"><\/td>\n<td width=\"66%\">\n<p>To change the ownership of a shared memory object.<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"20%\">\n<p><b>fchmod<\/b>(2)<\/p>\n<\/td>\n<td width=\"3%\"><\/td>\n<td width=\"66%\">\n<p>To change the permissions of a shared memory object.<\/p>\n<\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>Versions<\/b> <br \/> POSIX shared memory is supported since Linux 2.4 and glibc 2.2.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>Persistence<\/b> <br \/> 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>shm_unlink<\/b>(3)<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>Linking<\/b> <br \/> Programs using the POSIX shared memory API must be compiled with <i>cc \u2212lrt<\/i> to link against the real-time library, <i>librt<\/i>.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>Accessing shared memory objects via the filesystem<\/b> <br \/> On Linux, shared memory objects are created in a (<i>tmpfs<\/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.<\/p>\n<h2>NOTES <a name=\"NOTES\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">Typically, processes must synchronize their access to a shared memory object, using, for example, POSIX semaphores.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">System V shared memory (<b>shmget<\/b>(2), <b>shmop<\/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.<\/p>\n<h2>SEE ALSO <a name=\"SEE ALSO\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>fchmod<\/b>(2), <b>fchown<\/b>(2), <b>fstat<\/b>(2), <b>ftruncate<\/b>(2), <b>mmap<\/b>(2), <b>mprotect<\/b>(2), <b>munmap<\/b>(2), <b>shmget<\/b>(2), <b>shmop<\/b>(2), <b>shm_open<\/b>(3), <b>shm_unlink<\/b>(3), <b>sem_overview<\/b>(7)<\/p>\n<h2>COLOPHON <a name=\"COLOPHON\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">This page is part of release 5.10 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 https:\/\/www.kernel.org\/doc\/man\u2212pages\/.<\/p>\n<hr>\n","protected":false},"excerpt":{"rendered":"<p>  shm_overview \u2212 overview of POSIX shared memory <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[971],"tags":[973,972,1027],"class_list":["post-3934","post","type-post","status-publish","format-standard","hentry","category-7-miscelanea","tag-973","tag-man7","tag-shm_overview"],"gutentor_comment":0,"_links":{"self":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/3934","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/comments?post=3934"}],"version-history":[{"count":0,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/3934\/revisions"}],"wp:attachment":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/media?parent=3934"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/categories?post=3934"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/tags?post=3934"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}