1.\" $NetBSD: msgsnd.2,v 1.11 2002/02/08 01:28:19 ross Exp $ 2.\" 3.\" Copyright (c) 1995 Frank van der Linden 4.\" All rights reserved. 5.\" 6.\" Redistribution and use in source and binary forms, with or without 7.\" modification, are permitted provided that the following conditions 8.\" are met: 9.\" 1. Redistributions of source code must retain the above copyright 10.\" notice, this list of conditions and the following disclaimer. 11.\" 2. Redistributions in binary form must reproduce the above copyright 12.\" notice, this list of conditions and the following disclaimer in the 13.\" documentation and/or other materials provided with the distribution. 14.\" 3. All advertising materials mentioning features or use of this software 15.\" must display the following acknowledgement: 16.\" This product includes software developed for the NetBSD Project 17.\" by Frank van der Linden 18.\" 4. The name of the author may not be used to endorse or promote products 19.\" derived from this software without specific prior written permission 20.\" 21.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 22.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 23.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 24.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 25.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 26.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 30.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31.\" 32.Dd August 17, 1995 33.Dt MSGSND 2 34.Os 35.Sh NAME 36.Nm msgsnd 37.Nd send a message to a message queue 38.Sh LIBRARY 39.Lb libc 40.Sh SYNOPSIS 41.Fd #include \*[Lt]sys/msg.h\*[Gt] 42.Ft int 43.Fn msgsnd "int msqid" "const void *msgp" "size_t msgsz" "int msgflg" 44.Sh DESCRIPTION 45The 46.Fn msgsnd 47function sends a message from the message queue specified in 48.Fa msqid . 49.Fa msgp 50points to a user-defined structure containing the message. This structure 51must contain a first field of type 52.Sy long 53that will indicate the user-defined type of the message. The remaining 54fields will contain the contents of the message. The following is 55an example of what this user-defined structure might look like: 56.Bd -literal 57struct mymsg { 58 long mtype; /* message type */ 59 char mtext[1]; /* body of message */ 60}; 61.Ed 62.Pp 63.Va mtype 64is an integer greater than 0 that can be used for selecting messages (see 65.Xr msgrcv 2 ) . 66.Va mtext 67is an array of bytes, with size up to the system limit 68.Dv MSGMAX . 69.Pp 70If the number of bytes already on the message queue plus 71.Fa msgsz 72is greater than the maximum number of bytes in the message queue 73.Pf ( Va msg_qbytes , 74see 75.Xr msgctl 2 ) , 76or if the number of messages on all queues system-wide is already equal to 77the system limit, 78.Fa msgflg 79determines the action of 80.Fn msgsnd . 81If 82.Fa msgflg 83has 84.Dv IPC_NOWAIT 85mask set in it, the call will return immediately. If 86.Fa msgflg 87does not have 88.Dv IPC_NOWAIT 89set in it, the call will block until: 90.Bl -bullet 91.It 92The condition which caused the call to block no longer exists. 93The message was sent. 94.It 95The message queue is removed, in which case -1 will be returned and 96.Va errno 97set to 98.Er EINVAL . 99.It 100The caller catches a signal. The call returns with 101.Va errno 102set to 103.Er EINTR . 104.El 105.Pp 106After a successful call, the data structure associated with the message 107queue is updated in the following way: 108.Bl -bullet 109.It 110.Va msg_qnum 111is incremented by 1. 112.It 113.Va msg_lspid 114is set to the pid of the calling process. 115.It 116.Va msg_stime 117is set to the current time. 118.El 119.Sh RETURN VALUES 120Upon successful completion, 0 is returned. Otherwise, -1 is returned and 121.Va errno 122is set to indicate the error. 123.Sh ERRORS 124.Fn msgsnd 125will fail if: 126.Bl -tag -width Er 127.It Bq Er EINVAL 128.Fa msqid 129is not a valid message queue identifier, 130or the value of 131.Fa mtype 132is less than 1. 133.Pp 134The message queue was removed while 135.Fn msgsnd 136was waiting for a resource to become available in order to deliver the 137message. 138.Pp 139.Fa msgsz 140is less than 0, or greater than 141.Va msg_qbytes . 142.It Bq Er EACCES 143The calling process does not have write access to the message queue. 144.It Bq Er EAGAIN 145There was no space for this message either on the queue or in the whole 146system, and 147.Dv IPC_NOWAIT 148was set in 149.Fa msgflg . 150.It Bq Er EFAULT 151.Fa msgp 152points to an invalid address. 153.It Bq Er EINTR 154The system call was interrupted by the delivery of a signal. 155.El 156.Sh SEE ALSO 157.Xr msgctl 2 , 158.Xr msgget 2 , 159.Xr msgrcv 2 160.Sh STANDARDS 161The 162.Nm 163system call conforms to 164.St -xsh5 . 165.Sh HISTORY 166Message queues appeared in the first release of 167.At V . 168