Sending and Receiving Messages

Once you have a message queue to operate with, and the permissions are properly established, you can read and write messages to them. This section describes the msgsnd(3) and msgrcv(3) functions.

Sending Messages

Messages are sent using the msgsnd(3) function. Its function synopsis is given as follows:

#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/msg.h>

int msgsnd(int msqid, void *msgp, size_t msgsz, int msgflg);

The first argument msqid is the IPC ID of the message queue to send the message on. The argument msgp points to a message structure to be sent. The size of the message msgsz is the message size, not including the message type value. The msgflg argument is specified as 0 unless the flag

Get Advanced UNIX Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.