System V message queues

This is the classic AT&T message queue implementation suitable for messaging between an arbitrary number of unrelated processes. Sender processes wrap each message into a packet containing message data and a message number. The message queue implementation does not define the meaning of the message number, and it is left to the application designers to define appropriate meanings for message numbers and program readers and writers to interpret the same. This mechanism provides flexibility for programmers to use message numbers as message IDs or receiver IDs. It enables reader processes to selectively read messages that match specific IDs. However, messages with the same ID are always read in FIFO order (first in, first out).

Processes can create and open a SysV message queue with:

 int msgget(key_t key, int msgflg);

The key parameter is a unique constant that serves as a magic number to identify the message queue. All programs that are required to access this message queue will need to use the same magic number; this number is usually hard-coded into relevant processes at compile time. However, applications need to ensure that the key value is unique for each message queue, and there are alternate library functions available through which unique keys can be dynamically generated.

The unique key and msgflag parameter values, if set to IPC_CREATE, will cause a new message queue to be set up. Valid processes that have access to the queue can read or write messages into the queue using msgsnd and msgrcv routines (we will not discuss them in detail here; refer to Linux system programming manuals):

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

ssize_t msgrcv(int msqid, void *msgp, size_t msgsz, long msgtyp,
int msgflg);
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.174.168