⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 shm_open.html

📁 posix标准英文,html格式
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><meta name="generator" content="HTML Tidy, see www.w3.org"><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><link type="text/css" rel="stylesheet" href="style.css"><!-- Generated by The Open Group's rhtm tool v1.2.1 --><!-- Copyright (c) 2001-2004 IEEE and The Open Group, All Rights Reserved --><title>shm_open</title></head><body bgcolor="white"><script type="text/javascript" language="JavaScript" src="../jscript/codes.js"></script><basefont size="3"> <a name="shm_open"></a> <a name="tag_03_673"></a><!-- shm_open --> <!--header start--><center><font size="2">The Open Group Base Specifications Issue 6<br>IEEE Std 1003.1, 2004 Edition<br>Copyright &copy; 2001-2004 The IEEE and The Open Group, All Rights reserved.</font></center><!--header end--><hr size="2" noshade><h4><a name="tag_03_673_01"></a>NAME</h4><blockquote>shm_open - open a shared memory object (<b>REALTIME</b>)</blockquote><h4><a name="tag_03_673_02"></a>SYNOPSIS</h4><blockquote class="synopsis"><div class="box"><code><tt><sup>[<a href="javascript:open_code('SHM')">SHM</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0"> #include &lt;<a href="../basedefs/sys/mman.h.html">sys/mman.h</a>&gt;<br><br> int shm_open(const char *</tt><i>name</i><tt>, int</tt> <i>oflag</i><tt>, mode_t</tt> <i>mode</i><tt>); <img src="../images/opt-end.gif" alt="[Option End]" border="0"></tt></code></div><tt><br></tt></blockquote><h4><a name="tag_03_673_03"></a>DESCRIPTION</h4><blockquote><p>The <i>shm_open</i>() function shall establish a connection between a shared memory object and a file descriptor. It shallcreate an open file description that refers to the shared memory object and a file descriptor that refers to that open filedescription. The file descriptor is used by other functions to refer to that shared memory object. The <i>name</i> argument pointsto a string naming a shared memory object. It is unspecified whether the name appears in the file system and is visible to otherfunctions that take pathnames as arguments. The <i>name</i> argument conforms to the construction rules for a pathname. If<i>name</i> begins with the slash character, then processes calling <i>shm_open</i>() with the same value of <i>name</i> refer tothe same shared memory object, as long as that name has not been removed. If <i>name</i> does not begin with the slash character,the effect is implementation-defined. The interpretation of slash characters other than the leading slash character in <i>name</i>is implementation-defined.</p><p>If successful, <i>shm_open</i>() shall return a file descriptor for the shared memory object that is the lowest numbered filedescriptor not currently open for that process. The open file description is new, and therefore the file descriptor does not shareit with any other processes. It is unspecified whether the file offset is set. The FD_CLOEXEC file descriptor flag associated withthe new file descriptor is set.</p><p>The file status flags and file access modes of the open file description are according to the value of <i>oflag</i>. The<i>oflag</i> argument is the bitwise-inclusive OR of the following flags defined in the <a href="../basedefs/fcntl.h.html"><i>&lt;fcntl.h&gt;</i></a> header. Applications specify exactly one of the first two values (accessmodes) below in the value of <i>oflag</i>:</p><dl compact><dt>O_RDONLY</dt><dd>Open for read access only.</dd><dt>O_RDWR</dt><dd>Open for read or write access.</dd></dl><p>Any combination of the remaining flags may be specified in the value of <i>oflag</i>:</p><dl compact><dt>O_CREAT</dt><dd>If the shared memory object exists, this flag has no effect, except as noted under O_EXCL below. Otherwise, the shared memoryobject is created; the user ID of the shared memory object shall be set to the effective user ID of the process; the group ID ofthe shared memory object is set to a system default group ID or to the effective group ID of the process. The permission bits ofthe shared memory object shall be set to the value of the <i>mode</i> argument except those set in the file mode creation mask ofthe process. When bits in <i>mode</i> other than the file permission bits are set, the effect is unspecified. The <i>mode</i>argument does not affect whether the shared memory object is opened for reading, for writing, or for both. The shared memory objecthas a size of zero.</dd><dt>O_EXCL</dt><dd>If O_EXCL and O_CREAT are set, <i>shm_open</i>() fails if the shared memory object exists. The check for the existence of theshared memory object and the creation of the object if it does not exist is atomic with respect to other processes executing<i>shm_open</i>() naming the same shared memory object with O_EXCL and O_CREAT set. If O_EXCL is set and O_CREAT is not set, theresult is undefined.</dd><dt>O_TRUNC</dt><dd>If the shared memory object exists, and it is successfully opened O_RDWR, the object shall be truncated to zero length and themode and owner shall be unchanged by this function call. The result of using O_TRUNC with O_RDONLY is undefined.</dd></dl><p>When a shared memory object is created, the state of the shared memory object, including all data associated with the sharedmemory object, persists until the shared memory object is unlinked and all other references are gone. It is unspecified whether thename and shared memory object state remain valid after a system reboot.</p></blockquote><h4><a name="tag_03_673_04"></a>RETURN VALUE</h4><blockquote><p>Upon successful completion, the <i>shm_open</i>() function shall return a non-negative integer representing the lowest numberedunused file descriptor. Otherwise, it shall return -1 and set <i>errno</i> to indicate the error.</p></blockquote><h4><a name="tag_03_673_05"></a>ERRORS</h4><blockquote><p>The <i>shm_open</i>() function shall fail if:</p><dl compact><dt>[EACCES]</dt><dd>The shared memory object exists and the permissions specified by <i>oflag</i> are denied, or the shared memory object does notexist and permission to create the shared memory object is denied, or O_TRUNC is specified and write permission is denied.</dd><dt>[EEXIST]</dt><dd>O_CREAT and O_EXCL are set and the named shared memory object already exists.</dd><dt>[EINTR]</dt><dd>The <i>shm_open</i>() operation was interrupted by a signal.</dd><dt>[EINVAL]</dt><dd>The <i>shm_open</i>() operation is not supported for the given name.</dd><dt>[EMFILE]</dt><dd>Too many file descriptors are currently in use by this process.</dd><dt>[ENAMETOOLONG]</dt><dd>The length of the <i>name</i> argument exceeds {PATH_MAX} or a pathname component is longer than {NAME_MAX}.</dd><dt>[ENFILE]</dt><dd>Too many shared memory objects are currently open in the system.</dd><dt>[ENOENT]</dt><dd>O_CREAT is not set and the named shared memory object does not exist.</dd><dt>[ENOSPC]</dt><dd>There is insufficient space for the creation of the new shared memory object.</dd></dl></blockquote><hr><div class="box"><em>The following sections are informative.</em></div><h4><a name="tag_03_673_06"></a>EXAMPLES</h4><blockquote><h5><a name="tag_03_673_06_01"></a>Creating and Mapping a Shared Memory Object</h5>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -