msgop.2 (2010 09)
m
msgop(2) msgop(2)
NAME
msgsnd, msgrcv - message operations
SYNOPSIS
#include <sys/msg.h>
int msgsnd(
int msqid,
const void *msgp,
size_t msgsz,
int msgflg
);
int msgrcv(
int msqid,
void *msgp,
size_t msgsz,
long msgtyp,
int msgflg
);
DESCRIPTION
The msgsnd() system call sends a message to the queue associated with the message queue identifier
specified by msqid.
msgp points to a user-defined buffer that must contain first a field of type
long that specifies the type of
the message, followed by a data portion that will hold the data bytes of the message. The structure below
is an example of what this user-defined buffer might look like:
long mtype; /* message type */
char mtext[]; /* message text */
mtype is a positive integer that can be used by the receiving process for message selection (see
msgrcv()
below). mtext is any text of length msgsz bytes. msgsz can range from 0 to a system-imposed maximum.
msgflg specifies the action to be taken if one or more of the following is true:
• The number of bytes already on the queue is equal to
msg_qbytes (see message queue
identifier in glossary (9)).
• The total number of messages on all queues system-wide is equal to the system-imposed limit.
These actions are as follows:
If (msgflg
& IPC_NOWAIT) is true, the message is not sent and the calling process returns
immediately.
If (msgflg
& IPC_NOWAIT) is false, the calling process suspends execution until one of the follow-
ing occurs:
• The condition responsible for the suspension no longer exists, in which case the message is
sent.
• msqid is removed from the system (see msgctl (2)). When this occurs,
errno is set to [EIDRM]
and a value of -1 is returned.
• The calling process receives a signal to be caught. In this case, the message is not sent and the
calling process resumes execution in the manner prescribed in signal (5).
Upon successful completion, the following actions are taken with respect to the data structure 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
msgrcv() system call reads a message from the queue associated with the message queue identifier
specified by msqid and places it in the structure pointed to by msgp. This structure is composed of the
following members:
HP-UX 11i Version 3: September 2010 − 1 − Hewlett-Packard Company 1