SYNOPSIS
#include <sys/msg.h>
int msgsnd(int msqid, const void *msgp, size_t msgsz, int msgflg);
DESCRIPTION
The
If the call completes successfully, the following actions are taken with respect to the data structure (msqid_ds) associated with msqid:
- msg_qnum is incremented by 1.
- msg_lspid is set to the process ID of the calling process.
- msg_stime is set to the current time.
The argument msgp must point to a user-defined buffer that must contain first a field of type long int that specifies the type of the message, and then a data portion that holds the data bytes of the message. The following structure is an example of how a user-defined buffer might be declared:
struct mymsg { long int mtype; char mtext[1]; }
The structure member mtype is the message type, and the structure member mtext contains any text of length msgsz bytes. The argument msgsz can range from 0 to a system-imposed maximum.
PARAMETERS
- msqid
-
Is a unique positive integer, created by
msgget() , that identifies a message queue and its associated data structure. - msgp
-
Points to a user-defined buffer.
- msgsz
-
Is the length of the message to be sent.
- msgflg
-
Specifies the action to be taken if one or more of the following are true:
- The number of bytes already on the queue is equal to msg_qbytes from the msqid_ds data structure.
- The total number of messages on all queues system-wide is equal to the system-imposed limit.
If (msgflg & IPC_NOWAIT) is non-zero, the message is not sent and the calling process returns immediately. If (msgflg & IPC_NOWAIT) is zero, the calling process suspends execution until one of the following occurs:
- The condition responsible for the suspension no longer exists, in which case the message is sent.
- msqid is removed from the system. When this occurs, errno is set to EIDRM, and -1 is returned.
- The calling process receives a signal that is to be caught. In this case, the message is not sent and the calling process resumes execution as appropriate for the signal.
RETURN VALUES
If successful,
- EACCES
-
Operation permission is denied to the calling process.
- EFAULT
-
msgp is an invalid pointer.
- EIDRM
-
msqid was removed.
- EINTR
-
A signal interrupted the call.
- EINVAL
-
msgsz is less than 0 or greater than the system-imposed limit.
msqid is not a valid message queue identifier.
mtype is less than 1.
- ENOMSG
-
The message cannot be sent and (msgflg & IPC_NOWAIT) is non-zero.
CONFORMANCE
Unix 98.
MULTITHREAD SAFETY LEVEL
MT-Safe.
PORTING ISSUES
None.
AVAILABILITY
PTC MKS Toolkit for Professional Developers
PTC MKS Toolkit for Professional Developers 64-Bit Edition
PTC MKS Toolkit for Enterprise Developers
PTC MKS Toolkit for Enterprise Developers 64-Bit Edition
SEE ALSO
PTC MKS Toolkit 10.4 Documentation Build 39.