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

NAME

12       msgsnd - XSI message send operation
13

SYNOPSIS

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

DESCRIPTION

21       The msgsnd() function operates on XSI message queues (see the Base Def‐
22       initions volume of IEEE Std 1003.1-2001, Section 3.224, Message Queue).
23       It is unspecified whether this function interoperates with the realtime
24       interprocess communication facilities defined in 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
36              struct mymsg {
37                  long   mtype;       /* Message type. */
38                  char   mtext[1];    /* Message text. */
39              }
40
41       The structure member mtype is a non-zero positive type long that can be
42       used by the receiving process for message selection.
43
44       The structure member mtext is any text of length msgsz bytes. The argu‐
45       ment msgsz can range from 0 to a system-imposed maximum.
46
47       The argument msgflg specifies the action to be taken if one or more  of
48       the following is true:
49
50        * The number of bytes already on the queue is equal to msg_qbytes; see
51          <sys/msg.h>.
52
53        * The total number of messages on all queues system-wide is  equal  to
54          the system-imposed limit.
55
56       These actions are as follows:
57
58        * If  (msgflg & IPC_NOWAIT) is non-zero, the message shall not be sent
59          and the calling thread shall return immediately.
60
61        * If (msgflg & IPC_NOWAIT) is 0, the calling thread shall suspend exe‐
62          cution until one of the following occurs:
63
64           * The condition responsible for the suspension no longer exists, in
65             which case the message is sent.
66
67           * The message queue identifier msqid is removed  from  the  system;
68             when  this  occurs,  errno  shall  be set equal to [EIDRM] and -1
69             shall be returned.
70
71           * The calling thread receives a signal that is  to  be  caught;  in
72             this  case the message is not sent and the calling thread resumes
73             execution in the manner prescribed in sigaction().
74
75       Upon successful  completion,  the  following  actions  are  taken  with
76       respect to the data structure associated with msqid; see <sys/msg.h>:
77
78        * msg_qnum shall be incremented by 1.
79
80        * msg_lspid  shall  be  set  equal  to  the  process ID of the calling
81          process.
82
83        * msg_stime shall be set equal to the current time.
84

RETURN VALUE

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

ERRORS

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

EXAMPLES

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

APPLICATION USAGE

134       The  POSIX Realtime Extension defines alternative interfaces for inter‐
135       process communication (IPC). Application developers who need to use IPC
136       should design their applications so that modules using the IPC routines
137       described in XSI Interprocess Communication can be easily  modified  to
138       use the alternative interfaces.
139

RATIONALE

141       None.
142

FUTURE DIRECTIONS

144       None.
145

SEE ALSO

147       XSI  Interprocess  Communication,  Realtime,  mq_close(), mq_getattr(),
148       mq_notify(),   mq_open(),   mq_receive(),   mq_send(),    mq_setattr(),
149       mq_unlink(),  msgctl(), msgget(), msgrcv(), sigaction(), the Base Defi‐
150       nitions volume of IEEE Std 1003.1-2001, <sys/msg.h>
151
153       Portions of this text are reprinted and reproduced in  electronic  form
154       from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
155       -- Portable Operating System Interface (POSIX),  The  Open  Group  Base
156       Specifications  Issue  6,  Copyright  (C) 2001-2003 by the Institute of
157       Electrical and Electronics Engineers, Inc and The Open  Group.  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.opengroup.org/unix/online.html .
162
163
164
165IEEE/The Open Group                  2003                           MSGSND(3P)
Impressum