📄 shm_open.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"><html><head><!-- Copyright 1997 The Open Group, All Rights Reserved --><title>shm_open</title></head><body bgcolor=white><center><font size=2>The Single UNIX ® Specification, Version 2<br>Copyright © 1997 The Open Group</font></center><hr size=2 noshade><h4><a name = "tag_000_008_525"> </a>NAME</h4><blockquote>shm_open - open a shared memory object(<b>REALTIME</b>)</blockquote><h4><a name = "tag_000_008_526"> </a>SYNOPSIS</h4><blockquote><pre><code>#include <<a href="sysmman.h.html">sys/mman.h</a>>int shm_open(const char *<i>name</i>, int <i>oflag</i>, mode_t <i>mode</i>);</code></pre></blockquote><h4><a name = "tag_000_008_527"> </a>DESCRIPTION</h4><blockquote>The<i>shm_open()</i>function establishes a connection between a shared memory object anda file descriptor.It creates an open file description that refers to the shared memory object anda file descriptor that refers to that open file description.The file descriptor is used by other functions to refer to thatshared memory object.The<i>name</i>argument points to a string naming a shared memory object.It is unspecified whether the name appears in the file systemand is visible to other functions 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 to the 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-dependent.The interpretation of slashcharacters other than the leading slash character in<i>name</i>is implementation-dependent.<p>If successful,<i>shm_open()</i>returns a file descriptor for the shared memory objectthat is the lowest numbered file descriptornot currently open for that process.The open file description is new,and therefore the file descriptor does not share it with any other processes.It is unspecified whether the file offset is set.The FD_CLOEXECfile descriptor flag associated with the new file descriptor is set.<p>The file status flags and fileaccess modes of the open file description are according tothe value of<i>oflag</i>.The<i>oflag</i>argument is the bitwise inclusive OR of the following flagsdefined in the header<i><a href="fcntl.h.html"><fcntl.h></a></i>.Applications specify exactly one of the first two values(access modes) below in the value of<i>oflag</i>:<dl compact><dt>O_RDONLY<dd>Open for read access only.<dt>O_RDWR<dd>Open for read or write access.</dl><p>Any combination of the remaining flags may be specified in the value of<i>oflag</i>:<dl compact><dt>O_CREAT<dd>If the shared memory object exists, this flag has no effect,except as noted under O_EXCL below.Otherwise the shared memory object is created;the user ID of the shared memory objectwill be set to the effective user IDof the process;the group ID of the shared memory objectwill be set to a system default group IDor to the effective group ID of the process.The permission bits of the shared memory objectwill be set to the value of the<i>mode</i>argument except those set in the file mode creation mask of the 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 forreading, for writing, or for both.The shared memory object has a size of zero.<dt>O_EXCL<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 the shared memory objectand the creation of the objectif it does not exist is atomicwith 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, the result is undefined.<dt>O_TRUNC<dd>If the shared memory object exists,and it is successfully opened O_RDWR,the object will be truncated to zero lengthand the mode and owner will be unchanged by this function call.The result of using O_TRUNC with O_RDONLY is undefined.</dl><p>When a shared memory object is created, the state of the shared memory object,including all data associated with the shared memory object, persistsuntil the shared memory object is unlinked and all other references are gone.It is unspecified whether the name and shared memory object state remain validafter a system reboot.</blockquote><h4><a name = "tag_000_008_528"> </a>RETURN VALUE</h4><blockquote>Upon successful completion, the<i>shm_open()</i>function returns a non-negative integer representing the lowestnumbered unused file descriptor.Otherwise, it returns -1 and sets<i>errno</i>to indicate the error.</blockquote><h4><a name = "tag_000_008_529"> </a>ERRORS</h4><blockquote>The <i>shm_open()</i>function will fail if:<dl compact><dt>[EACCES]<dd><index term="[EACCES]"></index>The shared memory objectexists and the permissions specified by<i>oflag</i>are denied, or the shared memory objectdoes not exist and permission to createthe shared memory objectis denied, or O_TRUNCis specified and write permission is denied.<dt>[EEXIST]<dd><index term="[EEXIST]"></index>O_CREAT and O_EXCL are set andthe named shared memory objectalready exists.<dt>[EINTR]<dd>The<i>shm_open()</i>operation was interrupted by a signal.<dt>[EINVAL]<dd>The<i>shm_open()</i>operation is not supported for the given name.<dt>[EMFILE]<dd>Too manyfile descriptors are currently in use by this process.<dt>[ENAMETOOLONG]<dd>The length of the<i>name</i>string exceeds {PATH_MAX},or a pathname component is longer than {NAME_MAX}while _POSIX_NO_TRUNC is in effect.<dt>[ENFILE]<dd>Too many shared memory objectsare currently open in the system.<dt>[ENOENT]<dd>O_CREAT is not set and the namedshared memory object does not exist.<dt>[ENOSPC]<dd>There is insufficient space for the creation of the newshared memory object.<dt>[ENOSYS]<dd>The function<i>shm_open()</i>is not supported by this implementation.</dl></blockquote><h4><a name = "tag_000_008_530"> </a>EXAMPLES</h4><blockquote>None.</blockquote><h4><a name = "tag_000_008_531"> </a>APPLICATION USAGE</h4><blockquote>None.</blockquote><h4><a name = "tag_000_008_532"> </a>FUTURE DIRECTIONS</h4><blockquote>None.</blockquote><h4><a name = "tag_000_008_533"> </a>SEE ALSO</h4><blockquote><i><a href="close.html">close()</a></i>,<i><a href="dup.html">dup()</a></i>,<i><a href="exec.html">exec</a></i>,<i><a href="fcntl.html">fcntl()</a></i>,<i><a href="mmap.html">mmap()</a></i>,<i><a href="shmat.html">shmat()</a></i>,<i><a href="shmctl.html">shmctl()</a></i>,<i><a href="shmdt.html">shmdt()</a></i>,<i><a href="shm_unlink.html">shm_unlink()</a></i>,<i><a href="umask.html">umask()</a></i>,<i><a href="fcntl.h.html"><fcntl.h></a></i>,<i><a href="sysmman.h.html"><sys/mman.h></a></i>.<br></blockquote><h4>DERIVATION</h4><blockquote>Derived from the POSIX Realtime Extension (1003.1b-1993/1003.1i-1995)</blockquote><hr size=2 noshade><center><font size=2>UNIX ® is a registered Trademark of The Open Group.<br>Copyright © 1997 The Open Group<br> [ <a href="../index.html">Main Index</a> | <a href="../xshix.html">XSH</a> | <a href="../xcuix.html">XCU</a> | <a href="../xbdix.html">XBD</a> | <a href="../cursesix.html">XCURSES</a> | <a href="../xnsix.html">XNS</a> ]</font></center><hr size=2 noshade></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -