logo

oasis-root

Compiled tree of Oasis Linux based on own branch at <https://hacktivis.me/git/oasis/> git clone https://anongit.hacktivis.me/git/oasis-root.git

msgsnd.3p (6553B)


  1. '\" et
  2. .TH MSGSND "3P" 2017 "IEEE/The Open Group" "POSIX Programmer's Manual"
  3. .\"
  4. .SH PROLOG
  5. This manual page is part of the POSIX Programmer's Manual.
  6. The Linux implementation of this interface may differ (consult
  7. the corresponding Linux manual page for details of Linux behavior),
  8. or the interface may not be implemented on Linux.
  9. .\"
  10. .SH NAME
  11. msgsnd
  12. \(em XSI message send operation
  13. .SH SYNOPSIS
  14. .LP
  15. .nf
  16. #include <sys/msg.h>
  17. .P
  18. int msgsnd(int \fImsqid\fP, const void *\fImsgp\fP, size_t \fImsgsz\fP, int \fImsgflg\fP);
  19. .fi
  20. .SH DESCRIPTION
  21. The
  22. \fImsgsnd\fR()
  23. function operates on XSI message queues (see the Base Definitions volume of POSIX.1\(hy2017,
  24. .IR "Section 3.226" ", " "Message Queue").
  25. It is unspecified whether this function interoperates with the
  26. realtime interprocess communication facilities defined in
  27. .IR "Section 2.8" ", " "Realtime".
  28. .P
  29. The
  30. \fImsgsnd\fR()
  31. function shall send a message to the queue associated with the
  32. message queue identifier specified by
  33. .IR msqid .
  34. .P
  35. The application shall ensure that the argument
  36. .IR msgp
  37. points to a user-defined buffer that contains first a field of type
  38. .BR long
  39. specifying the type of the message, and then a data portion that holds
  40. the data bytes of the message. The structure below is an example of
  41. what this user-defined buffer might look like:
  42. .sp
  43. .RS 4
  44. .nf
  45. struct mymsg {
  46. long mtype; /* Message type. */
  47. char mtext[1]; /* Message text. */
  48. }
  49. .fi
  50. .P
  51. .RE
  52. .P
  53. The structure member
  54. .IR mtype
  55. is a non-zero positive type
  56. .BR long
  57. that can be used by the receiving process for message selection.
  58. .P
  59. The structure member
  60. .IR mtext
  61. is any text of length
  62. .IR msgsz
  63. bytes. The argument
  64. .IR msgsz
  65. can range from 0 to a system-imposed maximum.
  66. .P
  67. The argument
  68. .IR msgflg
  69. specifies the action to be taken if one or more of the following is
  70. true:
  71. .IP " *" 4
  72. The number of bytes already on the queue is equal to
  73. .BR msg_qbytes ;
  74. see
  75. .IR <sys/msg.h> .
  76. .IP " *" 4
  77. The total number of messages on all queues system-wide is equal to the
  78. system-imposed limit.
  79. .P
  80. These actions are as follows:
  81. .IP " *" 4
  82. If (\fImsgflg\fP & IPC_NOWAIT)
  83. is non-zero, the message shall not be sent and the calling thread
  84. shall return immediately.
  85. .IP " *" 4
  86. If (\fImsgflg\fP & IPC_NOWAIT) is 0, the calling thread shall suspend
  87. execution until one of the following occurs:
  88. .RS 4
  89. .IP -- 4
  90. The condition responsible for the suspension no longer exists, in which
  91. case the message is sent.
  92. .IP -- 4
  93. The message queue identifier
  94. .IR msqid
  95. is removed from the system; when this occurs,
  96. .IR errno
  97. shall be set to
  98. .BR [EIDRM]
  99. and \-1 shall be returned.
  100. .IP -- 4
  101. The calling thread receives a signal that is to be caught; in this case
  102. the message is not sent and the calling thread resumes execution in the
  103. manner prescribed in
  104. .IR "\fIsigaction\fR\^(\|)".
  105. .RE
  106. .br
  107. .P
  108. Upon successful completion, the following actions are taken with
  109. respect to the data structure associated with
  110. .IR msqid ;
  111. see
  112. .IR <sys/msg.h> :
  113. .IP " *" 4
  114. .BR msg_qnum
  115. shall be incremented by 1.
  116. .IP " *" 4
  117. .BR msg_lspid
  118. shall be set to the process ID of the calling process.
  119. .IP " *" 4
  120. .BR msg_stime
  121. shall be set to the current time, as described in
  122. .IR "Section 2.7.1" ", " "IPC General Description".
  123. .SH "RETURN VALUE"
  124. Upon successful completion,
  125. \fImsgsnd\fR()
  126. shall return 0; otherwise, no message shall be sent,
  127. \fImsgsnd\fR()
  128. shall return \-1, and
  129. .IR errno
  130. shall be set to indicate the error.
  131. .SH ERRORS
  132. The
  133. \fImsgsnd\fR()
  134. function shall fail if:
  135. .TP
  136. .BR EACCES
  137. Operation permission is denied to the calling process; see
  138. .IR "Section 2.7" ", " "XSI Interprocess Communication".
  139. .TP
  140. .BR EAGAIN
  141. The message cannot be sent for one of the reasons cited above and
  142. (\fImsgflg\fP & IPC_NOWAIT) is non-zero.
  143. .TP
  144. .BR EIDRM
  145. The message queue identifier
  146. .IR msqid
  147. is removed from the system.
  148. .TP
  149. .BR EINTR
  150. The
  151. \fImsgsnd\fR()
  152. function was interrupted by a signal.
  153. .TP
  154. .BR EINVAL
  155. The value of
  156. .IR msqid
  157. is not a valid message queue identifier, or the value of
  158. .IR mtype
  159. is less than 1; or the value of
  160. .IR msgsz
  161. is greater than the system-imposed limit.
  162. .LP
  163. .IR "The following sections are informative."
  164. .SH EXAMPLES
  165. .SS "Sending a Message"
  166. .P
  167. The following example sends a message to the queue identified by the
  168. .IR msqid
  169. argument (assuming that value has previously been set). This call
  170. specifies that an error should be reported if no message is available.
  171. The message size is calculated directly using the
  172. .IR sizeof
  173. operator.
  174. .sp
  175. .RS 4
  176. .nf
  177. #include <sys/msg.h>
  178. \&...
  179. int result;
  180. int msqid;
  181. struct message {
  182. long type;
  183. char text[20];
  184. } msg;
  185. .P
  186. msg.type = 1;
  187. strcpy(msg.text, "This is message 1");
  188. \&...
  189. result = msgsnd(msqid, (void *) &msg, sizeof(msg.text), IPC_NOWAIT);
  190. .fi
  191. .P
  192. .RE
  193. .SH "APPLICATION USAGE"
  194. The POSIX Realtime Extension defines alternative interfaces for interprocess communication
  195. (IPC). Application developers who need to use IPC should design their
  196. applications so that modules using the IPC routines described in
  197. .IR "Section 2.7" ", " "XSI Interprocess Communication"
  198. can be easily modified to use the alternative interfaces.
  199. .SH RATIONALE
  200. None.
  201. .SH "FUTURE DIRECTIONS"
  202. None.
  203. .SH "SEE ALSO"
  204. .IR "Section 2.7" ", " "XSI Interprocess Communication",
  205. .IR "Section 2.8" ", " "Realtime",
  206. .IR "\fImq_close\fR\^(\|)",
  207. .IR "\fImq_getattr\fR\^(\|)",
  208. .IR "\fImq_notify\fR\^(\|)",
  209. .IR "\fImq_open\fR\^(\|)",
  210. .IR "\fImq_receive\fR\^(\|)",
  211. .IR "\fImq_send\fR\^(\|)",
  212. .IR "\fImq_setattr\fR\^(\|)",
  213. .IR "\fImq_unlink\fR\^(\|)",
  214. .IR "\fImsgctl\fR\^(\|)",
  215. .IR "\fImsgget\fR\^(\|)",
  216. .IR "\fImsgrcv\fR\^(\|)",
  217. .IR "\fIsigaction\fR\^(\|)"
  218. .P
  219. The Base Definitions volume of POSIX.1\(hy2017,
  220. .IR "Section 3.226" ", " "Message Queue",
  221. .IR "\fB<sys_msg.h>\fP"
  222. .\"
  223. .SH COPYRIGHT
  224. Portions of this text are reprinted and reproduced in electronic form
  225. from IEEE Std 1003.1-2017, Standard for Information Technology
  226. -- Portable Operating System Interface (POSIX), The Open Group Base
  227. Specifications Issue 7, 2018 Edition,
  228. Copyright (C) 2018 by the Institute of
  229. Electrical and Electronics Engineers, Inc and The Open Group.
  230. In the event of any discrepancy between this version and the original IEEE and
  231. The Open Group Standard, the original IEEE and The Open Group Standard
  232. is the referee document. The original Standard can be obtained online at
  233. http://www.opengroup.org/unix/online.html .
  234. .PP
  235. Any typographical or formatting errors that appear
  236. in this page are most likely
  237. to have been introduced during the conversion of the source files to
  238. man page format. To report such errors, see
  239. https://www.kernel.org/doc/man-pages/reporting_bugs.html .