SYNOPSIS
#include <sys/msg.h>
int msgrcv(int msqid, void *msgp, int msgsz, long msgtyp, int msgflg);
DESCRIPTION
The
- msg_qnum is decremented by 1.
- msg_lrpid is set to the process ID of the calling process.
- msg_rtime 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 received message's type as specified by the sending process, and the structure member mtext is the text of the message.
The argument msgsz is the size in bytes of mtext. The received message is truncated to msgsz bytes if it is larger than msgsz and (msgflg & MSG_NOERROR) is non-zero. The truncated part of the message is lost, and no indication of the truncation is given to the calling process.
PARAMETERS
- msqid
-
Is a unique positive integer, created by a
msgget() call, that identifies a message queue. - msgp
-
Points to a user-defined buffer.
- msgsz
-
Specifies the size, in bytes, of mtext.
- msgtyp
-
Specifies the type of message requested as follows:
- msgflg
-
Specifies the action to be taken if a message of the desired type is not in the queue. The possible actions are:
- If (msgflg & IPC_NOWAIT) is non-zero, the calling process returns immediately with a return value of -1 and sets errno to ENOMSG.
- If (msgflg & IPC_NOWAIT) is zero, the calling process suspends execution until one of the following occurs:
- A message of the desired type is placed on the queue.
- msqid is removed from the system. When this occurs, errno is set to EIDRM, and a value of -1 is returned.
- The calling process receives a signal that is to be caught. In this case, a message is not received and the calling process resumes execution as appropriate for the signal.
RETURN VALUES
If successful,
- E2BIG
-
The length of mtext is greater than msgsz and (msgflg & MSG_NOERROR) is zero.
- 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.
msqid is not a valid message queue identifier.
- ENOMSG
-
The queue does not contain a message of the desired type and (msgtyp & 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.5 Documentation Build 40.