1.\" $NetBSD: msgsnd.2,v 1.15 2004/05/13 10:20:58 wiz 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.In sys/msg.h 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. 51This structure must contain a first field of type 52.Sy long 53that will indicate the user-defined type of the message. 54The remaining fields will contain the contents of the message. 55The following is an example of what this user-defined 56structure might look like: 57.Bd -literal 58struct mymsg { 59 long mtype; /* message type */ 60 char mtext[1]; /* body of message */ 61}; 62.Ed 63.Pp 64.Va mtype 65is an integer greater than 0 that can be used for selecting messages (see 66.Xr msgrcv 2 ) . 67.Va mtext 68is an array of bytes, with size up to the system limit 69.Dv MSGMAX . 70.Pp 71If the number of bytes already on the message queue plus 72.Fa msgsz 73is greater than the maximum number of bytes in the message queue 74.Pf ( Va msg_qbytes , 75see 76.Xr msgctl 2 ) , 77or if the number of messages on all queues system-wide is already equal to 78the system limit, 79.Fa msgflg 80determines the action of 81.Fn msgsnd . 82If 83.Fa msgflg 84has 85.Dv IPC_NOWAIT 86mask set in it, the call will return immediately. 87If 88.Fa msgflg 89does not have 90.Dv IPC_NOWAIT 91set in it, the call will block until: 92.Bl -bullet 93.It 94The condition which caused the call to block no longer exists. 95The message was sent. 96.It 97The message queue is removed, in which case \-1 will be returned and 98.Va errno 99set to 100.Er EINVAL . 101.It 102The caller catches a signal. 103The call returns with 104.Va errno 105set to 106.Er EINTR . 107.El 108.Pp 109After a successful call, the data structure associated with the message 110queue is updated in the following way: 111.Bl -bullet 112.It 113.Va msg_qnum 114is incremented by 1. 115.It 116.Va msg_lspid 117is set to the pid of the calling process. 118.It 119.Va msg_stime 120is set to the current time. 121.El 122.Sh RETURN VALUES 123Upon successful completion, 0 is returned. 124Otherwise, \-1 is returned and 125.Va errno 126is set to indicate the error. 127.Sh ERRORS 128.Fn msgsnd 129will fail if: 130.Bl -tag -width Er 131.It Bq Er EINVAL 132.Fa msqid 133is not a valid message queue identifier, 134or the value of 135.Fa mtype 136is less than 1. 137.Pp 138The message queue was removed while 139.Fn msgsnd 140was waiting for a resource to become available in order to deliver the 141message. 142.Pp 143.Fa msgsz 144is less than 0, or greater than 145.Va msg_qbytes . 146.It Bq Er EACCES 147The calling process does not have write access to the message queue. 148.It Bq Er EAGAIN 149There was no space for this message either on the queue or in the whole 150system, and 151.Dv IPC_NOWAIT 152was set in 153.Fa msgflg . 154.It Bq Er EFAULT 155.Fa msgp 156points to an invalid address. 157.It Bq Er EINTR 158The system call was interrupted by the delivery of a signal. 159.El 160.Sh SEE ALSO 161.Xr msgctl 2 , 162.Xr msgget 2 , 163.Xr msgrcv 2 164.Sh STANDARDS 165The 166.Nm 167system call conforms to 168.St -xsh5 . 169.Sh HISTORY 170Message queues appeared in the first release of 171.At V . 172