📄 shmat.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"><html><head><!-- Copyright 1997 The Open Group, All Rights Reserved --><title>shmat</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_543"> </a>NAME</h4><blockquote>shmat - shared memory attach operation</blockquote><h4><a name = "tag_000_008_544"> </a>SYNOPSIS</h4><blockquote><pre><code>#include <<a href="sysshm.h.html">sys/shm.h</a>>void *shmat(int <i>shmid</i>, const void *<i>shmaddr</i>, int <i>shmflg</i>);</code></pre></blockquote><h4><a name = "tag_000_008_545"> </a>DESCRIPTION</h4><blockquote>The<i>shmat()</i>functionattaches the shared memory segment associated withthe shared memory identifier specified by<i>shmid</i>to the address space of the calling process.The segment is attached at the addressspecified by one of the following criteria:<ul><p><li>If<i>shmaddr</i>is a null pointer, the segment is attached atthe first available address as selected by the system.<p><li>If<i>shmaddr</i>is not a null pointer and (<i>shmflg</i>&SHM_RND)is non-zero, the segment is attached at the address given by(<i>shmaddr</i>-((<i>uintptr_t</i>)<i>shmaddr</i>%SHMLBA))The character % is the C-language remainder operator.<p><li>If<i>shmaddr</i>is not a null pointer and (<i>shmflg</i>&SHM_RND)is 0, the segment is attached at the address given by<i>shmaddr</i>.<p><li>The segment is attached for reading if (<i>shmflg</i>&SHM_RDONLY)is non-zero and the calling process has read permission; otherwise, if it is 0and the calling process has read and write permission, the segment is attachedfor reading and writing.<p></ul></blockquote><h4><a name = "tag_000_008_546"> </a>RETURN VALUE</h4><blockquote>Upon successful completion,<i>shmat()</i>increments the value of<i>shm_nattch</i>in the data structure associated with the shared memory ID of the attachedshared memory segment and returns the segment's start address.<p>Otherwise, the shared memory segment is not attached,<i>shmat()</i>returns -1 and<i>errno</i>is set to indicate the error.</blockquote><h4><a name = "tag_000_008_547"> </a>ERRORS</h4><blockquote>The<i>shmat()</i>function will fail if:<dl compact><dt>[EACCES]<dd>Operation permission is denied to the calling process,see<a href="ipc.html">IPC</a>.<dt>[EINVAL]<dd>The value of<i>shmid</i>is not a valid shared memory identifier;the<i>shmaddr</i>is not a null pointer and the value of(<i>shmaddr</i>-((<i>ptrdiff_t</i>)<i>shmaddr</i>%SHMLBA))is an illegal address for attaching shared memory;or the<i>shmaddr</i>is not a null pointer, (<i>shmflg</i>&SHM_RND) is 0 and the value of<i>shmaddr</i>is an illegal address for attaching shared memory.<dt>[EMFILE]<dd>The number of shared memory segments attached to thecalling process would exceed the system-imposed limit.<dt>[ENOMEM]<dd>The available data space is not large enoughto accommodate the shared memory segment.</dl></blockquote><h4><a name = "tag_000_008_548"> </a>EXAMPLES</h4><blockquote>None.</blockquote><h4><a name = "tag_000_008_549"> </a>APPLICATION USAGE</h4><blockquote>The POSIX Realtime Extension defines alternative interfaces for interprocess communication.Application developers who need to use IPC should design theirapplications so that modules using the IPC routines described in<a href="ipc.html">IPC</a>can be easily modified to use the alternative interfaces.</blockquote><h4><a name = "tag_000_008_550"> </a>FUTURE DIRECTIONS</h4><blockquote>None.</blockquote><h4><a name = "tag_000_008_551"> </a>SEE ALSO</h4><blockquote><i><a href="exec.html">exec</a></i>,<i><a href="exit.html">exit()</a></i>,<i><a href="fork.html">fork()</a></i>,<i><a href="shmctl.html">shmctl()</a></i>,<i><a href="shmdt.html">shmdt()</a></i>,<i><a href="shmget.html">shmget()</a></i>,<i><a href="shm_open.html">shm_open()</a></i>,<i><a href="shm_unlink.html">shm_unlink()</a></i>,<i><a href="sysshm.h.html"><sys/shm.h></a></i>,<a href="ipc.html">IPC</a>.</blockquote><h4>DERIVATION</h4><blockquote>Derived from Issue 2 of the SVID.</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 + -