msgsnd() - send message to message queue
#include <sys/msg.h>
int msgsnd (int msqid, const void *msgp, size_t msgsz, int msgflg)
The msgsnd(2) function sends a message to the queue associated with the identifier msqid. The message is held in the data structure pointed to by msgp; the size of the message in bytes is indicated by msgsz, and can be any value from 0 to the system limit. The msgflg argument specifies what is to be done if the queue already holds the maximum number of bytes or if the total number of messages on all queues on the system meets the system-imposed limit. The important instruction for msgflg is IPC_NOWAIT.
When the msgsnd(2) function succeeds, the data structure associated with msqid is modified:
The msgp structure is defined by the user, but the first member must be a non-zero positive long int which holds a value used for selecting messages. The second member must hold the data text. The length must be the same as msgsz.
If the message queue is full, or if the system-limit on queued messages is reached, the behavior of msgsnd(2) depends upon the value of msgflg:
The msgsnd(2) function returns 0 on success. On failure, it returns -1, doesn't send the message, and sets errno to indicate the error.
A simple structure for data which sends four-character strings as messages might be:
struct a_msg {
long int msg_type; /* message type */
char msg_text[5]; /* message text */
};
For this structure, the value of msgsz would be 5.
msgctl(2)
msgget(2)
msgrcv(2)