Sends a message.
Standard C Library (libc.a)
int msgsnd (MessageQueueID, MessagePointer,MessageSize, MessageFlag) int MessageQueueID, MessageFlag; const void *MessagePointer; size_t MessageSize;
The msgsnd subroutine sends a message to the queue specified by the MessageQueueID parameter. The current process must have write permission to perform this operation. The MessagePointer parameter points to an msgbuf structure containing the message. The sys/msg.h file defines the msgbuf structure. The structure contains the following fields:
mtyp_t mtype; /* Message type */ char mtext; /* Beginning of message text */
The mtype field specifies a positive integer used by the receiving process for message selection. The mtext field can be any text of the length in bytes specified by the MessageSize parameter. The MessageSize parameter can range from 0 to the maximum limit imposed by the system.
The following example shows a typical user-defined msgbuf structure that includes sufficient space for the largest message:struct my_msgbuf
Note: The routine may coredump instead of returning EFAULT when an invalid pointer is passed in case of 64-bit application calling 32-bit kernel interface.
The following system limits apply to the message queue:
Note: For a 64-bit process, the mtype field is 64 bits long. However, for compatibility with 32-bit processes, the most significant 32 bits must be 0 and will not be put on the message queue. For a 64-bit receiver process, the mtype will again be extended to 64 bits with the most significant bits 0.
The MessageFlag parameter specifies the action to be taken if the message cannot be sent for one of the following reasons:
These actions are as follows:
|MessageQueueID||Specifies the queue to which the message is sent.|
|MessagePointer||Points to a msgbuf structure containing the message.|
|MessageSize||Specifies the length, in bytes, of the message text.|
|MessageFlag||Specifies the action to be taken if the message cannot be sent.|
Upon successful completion, a value of 0 is returned and the following actions are taken with respect to the data structure associated with the MessageQueueID parameter:
If the msgsnd subroutine is unsuccessful, a value of -1 is returned and the errno global variable is set to indicate the error.
The msgsnd subroutine is unsuccessful and no message is sent if one or more of the following conditions is true:
|EINVAL||The MessageQueueID parameter is not a valid message queue identifier.|
|EACCES||The calling process is denied permission for the specified operation.|
|EINVAL||The mtype field is less than 1.|
|EAGAIN||The message cannot be sent for one of the reasons stated previously, and the MessageFlag parameter is set to the IPC_NOWAIT value.|
|EINVAL||The MessageSize parameter is less than 0 or greater than the system-imposed limit.|
|EFAULT||The MessagePointer parameter points outside of the address space of the process.|
|EINTR||The msgsnd subroutine received a signal.|
|EIDRM||The message queue identifier specified by the MessageQueueID parameter has been removed from the system.|
|ENOMEM||The message could not be sent because not enough storage space was available.|
|EINVAL||The upper 32-bits of the 64-bit mtype field for a 64-bit process is not 0.|
This subroutine is part of Base Operating System (BOS) Runtime.
The msgctl subroutine, msgget subroutine, msgrcv subroutine, msgxrcv subroutine, sigaction subroutine.