📄 msgsnd.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"><html><head><!-- Copyright 1997 The Open Group, All Rights Reserved --><title>msgsnd</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_007_826"> </a>NAME</h4><blockquote>msgsnd - message send operation</blockquote><h4><a name = "tag_000_007_827"> </a>SYNOPSIS</h4><blockquote><pre><code>#include <<a href="sysmsg.h.html">sys/msg.h</a>>int msgsnd(int <i>msqid</i>, const void *<i>msgp</i>, size_t <i>msgsz</i>, int <i>msgflg</i>);</code></pre></blockquote><h4><a name = "tag_000_007_828"> </a>DESCRIPTION</h4><blockquote>The<i>msgsnd()</i>function is used to send a message to the queueassociated with the message queue identifier specified by<i>msqid</i>.<p>The argument<i>msgp</i>points to a user-defined buffer that must containfirst a field of type<b>long int</b>that will specify the type of the message,and then a data portion that will hold the data bytes of the message.The structure below is an example of whatthis user-defined buffer might look like:<pre><code>struct mymsg { long int mtype; /* message type */ char mtext[1]; /* message text */}</code></pre>The structure member<b>mtype</b>is a non-zero positive type <b>long int</b> that can be usedby the receiving process for message selection.<p>The structure member<b>mtext</b>is any text of length<i>msgsz</i>bytes.The argument<i>msgsz</i>can range from 0 to a system-imposed maximum.<p>The argument<i>msgflg</i>specifies the action to be taken if one or more of the following are true:<ul><p><li>The number of bytes already on the queue is equal to<b>msg_qbytes</b>,see<i><a href="sysmsg.h.html"><sys/msg.h></a></i>.<p><li>The total number of messages on all queuessystem-wide is equal to the system-imposed limit.<p></ul><p>These actions are as follows:<ul><p><li>If (<i>msgflg</i> & IPC_NOWAIT)is non-zero, the message will not besent and the calling thread will return immediately.<p><li>If (<i>msgflg</i> & IPC_NOWAIT)is 0, the calling thread will suspend execution untilone of the following occurs:<ul><p><li>The condition responsible for the suspension no longer exists,in which case the message is sent.<p><li>The message queue identifier<i>msqid</i>is removed from the system; when this occurs,<i>errno</i>is set equal to [EIDRM] and -1 is returned.<p><li>The calling thread receives a signal that is to be caught;in this case the message is not sentand the calling thread resumes execution in the mannerprescribed in<i><a href="sigaction.html">sigaction()</a></i>.<p></ul><p></ul><p>Upon successful completion, the following actions are takenwith respect to the data structure associated with<i>msqid</i>,see<i><a href="sysmsg.h.html"><sys/msg.h></a></i>:<ul><p><li><b>msg_qnum</b>is incremented by 1.<p><li><b>msg_lspid</b>is set equal to the process ID of the calling process.<p><li><b>msg_stime</b>is set equal to the current time.<p></ul><br></blockquote><h4><a name = "tag_000_007_829"> </a>RETURN VALUE</h4><blockquote>Upon successful completion,<i>msgsnd()</i>returns 0. Otherwise, no message will be sent,<i>msgsnd()</i>will return -1 and<i>errno</i>will be set to indicate the error.</blockquote><h4><a name = "tag_000_007_830"> </a>ERRORS</h4><blockquote>The<i>msgsnd()</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>[EAGAIN]<dd>The message cannot be sent for one of the reasons cited above and(<i>msgflg</i> & IPC_NOWAIT) is non-zero.<dt>[EIDRM]<dd>The message queue identifier<i>msgid</i>is removed from the system.<dt>[EINTR]<dd>The<i>msgsnd()</i>function was interrupted by a signal.<dt>[EINVAL]<dd>The value of<i>msqid</i>is not a valid message queue identifier,or the value of<b>mtype</b>is less than 1; or the value of<i>msgsz</i>is less than 0 or greater than the system-imposed limit.</dl></blockquote><h4><a name = "tag_000_007_831"> </a>EXAMPLES</h4><blockquote>None.</blockquote><h4><a name = "tag_000_007_832"> </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_007_833"> </a>FUTURE DIRECTIONS</h4><blockquote>None.</blockquote><h4><a name = "tag_000_007_834"> </a>SEE ALSO</h4><blockquote><i><a href="mq_close.html">mq_close()</a></i>,<i><a href="mq_getattr.html">mq_getattr()</a></i>,<i><a href="mq_notify.html">mq_notify()</a></i>,<i><a href="mq_open.html">mq_open()</a></i>,<i><a href="mq_receive.html">mq_receive()</a></i>,<i><a href="mq_send.html">mq_send()</a></i>,<i><a href="mq_setattr.html">mq_setattr()</a></i>,<i><a href="mq_unlink.html">mq_unlink()</a></i>,<i><a href="msgctl.html">msgctl()</a></i>,<i><a href="msgget.html">msgget()</a></i>,<i><a href="msgrcv.html">msgrcv()</a></i>,<i><a href="sigaction.html">sigaction()</a></i>,<i><a href="sysmsg.h.html"><sys/msg.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 + -