📄 shmat.html
字号:
<!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>shmat</title></head><body bgcolor="white"><script type="text/javascript" language="JavaScript" src="../jscript/codes.js"></script><basefont size="3"> <a name="shmat"></a> <a name="tag_03_675"></a><!-- shmat --> <!--header start--><center><font size="2">The Open Group Base Specifications Issue 6<br>IEEE Std 1003.1, 2004 Edition<br>Copyright © 2001-2004 The IEEE and The Open Group, All Rights reserved.</font></center><!--header end--><hr size="2" noshade><h4><a name="tag_03_675_01"></a>NAME</h4><blockquote>shmat - XSI shared memory attach operation</blockquote><h4><a name="tag_03_675_02"></a>SYNOPSIS</h4><blockquote class="synopsis"><div class="box"><code><tt><sup>[<a href="javascript:open_code('XSI')">XSI</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0"> #include <<a href="../basedefs/sys/shm.h.html">sys/shm.h</a>><br><br> void *shmat(int</tt> <i>shmid</i><tt>, const void *</tt><i>shmaddr</i><tt>, int</tt> <i>shmflg</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_675_03"></a>DESCRIPTION</h4><blockquote><p>The <i>shmat</i>() function operates on XSI shared memory (see the Base Definitions volume of IEEE Std 1003.1-2001, <ahref="../basedefs/xbd_chap03.html#tag_03_340">Section 3.340, Shared Memory Object</a>). It is unspecified whether this functioninteroperates with the realtime interprocess communication facilities defined in <a href="xsh_chap02_08.html#tag_02_08"><i>Realtime</i></a>.</p><p>The <i>shmat</i>() function attaches the shared memory segment associated with the shared memory identifier specified by<i>shmid</i> to the address space of the calling process. The segment is attached at the address specified by one of the followingcriteria:</p><ul><li><p>If <i>shmaddr</i> is a null pointer, the segment is attached at the first available address as selected by the system.</p></li><li><p>If <i>shmaddr</i> is not a null pointer and (<i>shmflg</i> &SHM_RND) is non-zero, the segment is attached at the addressgiven by (<i>shmaddr</i> -((<i>uintptr_t</i>)<i>shmaddr</i> %SHMLBA)). The character <tt>'%'</tt> is the C-language remainderoperator.</p></li><li><p>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><li><p>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 0 and the calling process has read and write permission, the segment is attached for reading and writing.</p></li></ul></blockquote><h4><a name="tag_03_675_04"></a>RETURN VALUE</h4><blockquote><p>Upon successful completion, <i>shmat</i>() shall increment the value of <i>shm_nattch</i> in the data structure associated withthe shared memory ID of the attached shared memory segment and return the segment's start address.</p><p>Otherwise, the shared memory segment shall not be attached, <i>shmat</i>() shall return -1, and <i>errno</i> shall be set toindicate the error.</p></blockquote><h4><a name="tag_03_675_05"></a>ERRORS</h4><blockquote><p>The <i>shmat</i>() function shall fail if:</p><dl compact><dt>[EACCES]</dt><dd>Operation permission is denied to the calling process; see <a href="xsh_chap02_07.html#tag_02_07"><i>XSI InterprocessCommunication</i></a>.</dd><dt>[EINVAL]</dt><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>uintptr_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 forattaching shared memory.</dd><dt>[EMFILE]</dt><dd>The number of shared memory segments attached to the calling process would exceed the system-imposed limit.</dd><dt>[ENOMEM]</dt><dd>The available data space is not large enough to accommodate the shared memory segment.</dd></dl></blockquote><hr><div class="box"><em>The following sections are informative.</em></div><h4><a name="tag_03_675_06"></a>EXAMPLES</h4><blockquote><p>None.</p></blockquote><h4><a name="tag_03_675_07"></a>APPLICATION USAGE</h4><blockquote><p>The POSIX Realtime Extension defines alternative interfaces for interprocess communication. Application developers who need touse IPC should design their applications so that modules using the IPC routines described in <a href="xsh_chap02_07.html#tag_02_07"><i>XSI Interprocess Communication</i></a> can be easily modified to use the alternativeinterfaces.</p></blockquote><h4><a name="tag_03_675_08"></a>RATIONALE</h4><blockquote><p>None.</p></blockquote><h4><a name="tag_03_675_09"></a>FUTURE DIRECTIONS</h4><blockquote><p>None.</p></blockquote><h4><a name="tag_03_675_10"></a>SEE ALSO</h4><blockquote><p><a href="xsh_chap02_07.html#tag_02_07"><i>XSI Interprocess Communication</i></a>, <a href="xsh_chap02_08.html#tag_02_08"><i>Realtime</i></a>, <a href="exec.html"><i><a href="../functions/exec.html">exec</a></i>()</a>,<a href="exit.html"><i>exit</i>()</a>, <a href="fork.html"><i>fork</i>()</a>, <a href="shmctl.html"><i>shmctl</i>()</a>, <ahref="shmdt.html"><i>shmdt</i>()</a>, <a href="shmget.html"><i>shmget</i>()</a>, <a href="shm_open.html"><i>shm_open</i>()</a>,<a href="shm_unlink.html"><i>shm_unlink</i>()</a>, the Base Definitions volume of IEEE Std 1003.1-2001, <a href="../basedefs/sys/shm.h.html"><i><sys/shm.h></i></a></p></blockquote><h4><a name="tag_03_675_11"></a>CHANGE HISTORY</h4><blockquote><p>First released in Issue 2. Derived from Issue 2 of the SVID.</p></blockquote><h4><a name="tag_03_675_12"></a>Issue 5</h4><blockquote><p>Moved from SHARED MEMORY to BASE.</p><p>The note about use of POSIX Realtime Extension IPC routines has been moved from FUTURE DIRECTIONS to a new APPLICATION USAGEsection.</p></blockquote><h4><a name="tag_03_675_13"></a>Issue 6</h4><blockquote><p>The Open Group Corrigendum U021/13 is applied.</p></blockquote><div class="box"><em>End of informative text.</em></div><hr size="2" noshade><center><font size="2"><!--footer start-->UNIX ® is a registered Trademark of The Open Group.<br>POSIX ® is a registered Trademark of The IEEE.<br>[ <a href="../mindex.html">Main Index</a> | <a href="../basedefs/contents.html">XBD</a> | <a href="../utilities/contents.html">XCU</a> | <a href="../functions/contents.html">XSH</a> | <a href="../xrat/contents.html">XRAT</a>]</font></center><!--footer end--><hr size="2" noshade></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -