1MSGSND(3P)                 POSIX Programmer's Manual                MSGSND(3P)
2
3
4

PROLOG

6       This  manual  page is part of the POSIX Programmer's Manual.  The Linux
7       implementation of this interface may differ (consult the  corresponding
8       Linux  manual page for details of Linux behavior), or the interface may
9       not be implemented on Linux.
10
11

NAME

13       msgsnd — XSI message send operation
14

SYNOPSIS

16       #include <sys/msg.h>
17
18       int msgsnd(int msqid, const void *msgp, size_t msgsz, int msgflg);
19

DESCRIPTION

21       The msgsnd() function operates on XSI message queues (see the Base Def‐
22       initions  volume of POSIX.1‐2008, Section 3.225, Message Queue).  It is
23       unspecified whether  this  function  interoperates  with  the  realtime
24       interprocess communication facilities defined in Section 2.8, Realtime.
25
26       The msgsnd() function shall send a message to the queue associated with
27       the message queue identifier specified by msqid.
28
29       The application shall ensure that the argument msgp points to  a  user-
30       defined  buffer that contains first a field of type long specifying the
31       type of the message, and then a data portion that holds the data  bytes
32       of  the  message.  The structure below is an example of what this user-
33       defined buffer might look like:
34
35           struct mymsg {
36               long   mtype;       /* Message type. */
37               char   mtext[1];    /* Message text. */
38           }
39
40       The structure member mtype is a non-zero positive type long that can be
41       used by the receiving process for message selection.
42
43       The structure member mtext is any text of length msgsz bytes. The argu‐
44       ment msgsz can range from 0 to a system-imposed maximum.
45
46       The argument msgflg specifies the action to be taken if one or more  of
47       the following is true:
48
49        *  The  number  of  bytes already on the queue is equal to msg_qbytes;
50           see <sys/msg.h>.
51
52        *  The total number of messages on all queues system-wide is equal  to
53           the system-imposed limit.
54
55       These actions are as follows:
56
57        *  If (msgflg & IPC_NOWAIT) is non-zero, the message shall not be sent
58           and the calling thread shall return immediately.
59
60        *  If (msgflg & IPC_NOWAIT) is 0, the  calling  thread  shall  suspend
61           execution until one of the following occurs:
62
63           --  The  condition responsible for the suspension no longer exists,
64               in which case the message is sent.
65
66           --  The message queue identifier msqid is removed from the  system;
67               when this occurs, errno shall be set to [EIDRM] and −1 shall be
68               returned.
69
70           --  The calling thread receives a signal that is to be  caught;  in
71               this  case  the  message  is  not  sent  and the calling thread
72               resumes execution in the manner prescribed in sigaction().
73
74       Upon successful  completion,  the  following  actions  are  taken  with
75       respect to the data structure associated with msqid; see <sys/msg.h>:
76
77        *  msg_qnum shall be incremented by 1.
78
79        *  msg_lspid shall be set to the process ID of the calling process.
80
81        *  msg_stime shall be set to the current time, as described in Section
82           2.7.1, IPC General Description.
83

RETURN VALUE

85       Upon successful completion, msgsnd() shall return 0; otherwise, no mes‐
86       sage shall be sent, msgsnd() shall return −1, and errno shall be set to
87       indicate the error.
88

ERRORS

90       The msgsnd() function shall fail if:
91
92       EACCES Operation permission is denied to the calling process; see  Sec‐
93              tion 2.7, XSI Interprocess Communication.
94
95       EAGAIN The  message  cannot  be sent for one of the reasons cited above
96              and (msgflg & IPC_NOWAIT) is non-zero.
97
98       EIDRM  The message queue identifier msqid is removed from the system.
99
100       EINTR  The msgsnd() function was interrupted by a signal.
101
102       EINVAL The value of msqid is not a valid message queue  identifier,  or
103              the  value  of  mtype  is  less than 1; or the value of msgsz is
104              greater than the system-imposed limit.
105
106       The following sections are informative.
107

EXAMPLES

109   Sending a Message
110       The following example sends a message to the queue  identified  by  the
111       msqid argument (assuming that value has previously been set). This call
112       specifies that an error should be reported if no message is  available.
113       The message size is calculated directly using the sizeof operator.
114
115           #include <sys/msg.h>
116           ...
117           int result;
118           int msqid;
119           struct message {
120               long type;
121               char text[20];
122           } msg;
123
124           msg.type = 1;
125           strcpy(msg.text, "This is message 1");
126           ...
127           result = msgsnd(msqid, (void *) &msg, sizeof(msg.text), IPC_NOWAIT);
128

APPLICATION USAGE

130       The  POSIX Realtime Extension defines alternative interfaces for inter‐
131       process communication (IPC). Application developers who need to use IPC
132       should design their applications so that modules using the IPC routines
133       described in Section 2.7, XSI Interprocess Communication can be  easily
134       modified to use the alternative interfaces.
135

RATIONALE

137       None.
138

FUTURE DIRECTIONS

140       None.
141

SEE ALSO

143       Section  2.7,  XSI  Interprocess  Communication, Section 2.8, Realtime,
144       mq_close(),   mq_getattr(),   mq_notify(),   mq_open(),   mq_receive(),
145       mq_send(),  mq_setattr(),  mq_unlink(),  msgctl(),  msgget(), msgrcv(),
146       sigaction()
147
148       The Base Definitions volume of  POSIX.1‐2008,  Section  3.225,  Message
149       Queue, <sys_msg.h>
150
152       Portions  of  this text are reprinted and reproduced in electronic form
153       from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology
154       --  Portable  Operating  System  Interface (POSIX), The Open Group Base
155       Specifications Issue 7, Copyright (C) 2013 by the Institute of Electri‐
156       cal  and  Electronics  Engineers,  Inc  and  The  Open Group.  (This is
157       POSIX.1-2008 with the 2013 Technical Corrigendum  1  applied.)  In  the
158       event of any discrepancy between this version and the original IEEE and
159       The Open Group Standard, the original IEEE and The Open Group  Standard
160       is  the  referee document. The original Standard can be obtained online
161       at http://www.unix.org/online.html .
162
163       Any typographical or formatting errors that appear  in  this  page  are
164       most likely to have been introduced during the conversion of the source
165       files to man page format. To report such errors,  see  https://www.ker
166       nel.org/doc/man-pages/reporting_bugs.html .
167
168
169
170IEEE/The Open Group                  2013                           MSGSND(3P)
Impressum