Chapter Contents

Previous

Next
msgsnd

msgsnd



Send a Message to a Message Queue

Portability: UNIX compatible


SYNOPSIS
DESCRIPTION
RETURN VALUE
USAGE NOTES
EXAMPLE 1
EXAMPLE 2
EXAMPLE 3
EXAMPLE 4
RELATED FUNCTIONS


SYNOPSIS

#include <sys/msg.h>
int msgsnd(int id, const void *msg,
           size_t size, int flags);


DESCRIPTION

The msgsnd function is used to send a message to an UNIX System Services message queue, for later receipt by another process calling msgrcv or msgxrcv .

Note:   See the msgget function description in section msgget for general information about message queues.  [cautionend]
The id argument to msgsnd specifies the id of the message queue to which messages will be sent. This argument is an id, such as the id returned by msgget , not a message queue key, which might be passed as an argument to msgget .

The msg argument should be a pointer to a message buffer that contains the message to be sent. The message buffer should have the following layout:

struct {
   long mtype;     /* message type */
   char mtext[n];  /* message text */
};

where n is an integer constant large enough for the message text.

Note:   You must declare an appropriate type for the messages you send yourself, as no such type is defined by sys/msg.h . Also the meaning of mtype is not fixed by the message queue protocol (other than that its value must be greater than zero), but it can be used by the application to establish message types or priorities in any natural way.  [cautionend]
The size argument to msgsnd should be the number of bytes of message text to be sent. size should not include the size of the mtype field. It is possible to send a message which contains only a type, but no text, in which case a size of 0 should be passed.

The flags argument specifies either 0 or the IPC_NOWAIT option. If IPC_NOWAIT is set, and the system limits on the amount of queued up data have been reached, the call to msgsnd will immediately fail, with errno set to EAGAIN . If IPC_NOWAIT is not set, and the limits have been reached, the calling process will wait until enough messages are removed from the queue to allow this message to be sent.


RETURN VALUE

msgsnd returns 0 if successful, or -1 if unsuccessful.


USAGE NOTES

The msgsnd function can only be used with MVS 5.2.2 or a later release.


EXAMPLE 1

Refer to msgget for an example.


EXAMPLE 2

Refer to msgctl for an example that establishes an IPC Server using Message Queues.


EXAMPLE 3

Refer to msgget for an example that establishes IPC Client using XMessage Queues.


EXAMPLE 4

Refer to msgctl for an example that establishes an IPC Server using Message Queues. Also, it uses UNIX System Service's extended Message structure.


RELATED FUNCTIONS

msgctl , msgget , msgrcv , msgxrcv


Chapter Contents

Previous

Next

Top of Page

Copyright © 2001 by SAS Institute Inc., Cary, NC, USA. All rights reserved.