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