

The first argument, key, recognizes the message queue. This system call creates or allocates a System V message queue. Now, let us check the syntax and certain information on the above calls. Step 4 − Perform control operations on the message queue (msgctl())

Step 3 − Read from the message queue (msgrcv()) Step 2 − Write into message queue (msgsnd()) Step 1 − Create a message queue or connect to an already existing message queue (msgget()) To perform communication using message queues, following are the steps − Having seen certain information on message queues, now it is time to check for the system call (System V) which supports the message queues. Writing into the shared memory by one process with different data packets and reading from it by multiple processes, i.e., as per message type. As we are aware, reading can be done with multiple processes as well. Writing into the shared memory by one process and reading from the shared memory by another process. Using Shared Memory or Message Queues depends on the need of the application and how effectively it can be utilized.Ĭommunication using message queues can happen in the following ways −

The first message inserted in the queue is the first one to be retrieved. Ofcourse, the order of message queue is FIFO (First In First Out). To simplify the given message type as 1, 10, 20, it can be either 0 or +ve or –ve as discussed below. In this case, it is simplier to implement with message queues. If we want to communicate with different data packets, say process A is sending message type 1 to process B, message type 10 to process C, and message type 20 to process D. What if all the processes do not need to access the shared memory but very few processes only need it, it would be better to implement with message queues. Not worth with regard to utilization in this kind of cases. Shared memory data need to be protected with synchronization when multiple processes communicating at the same time.įrequency of writing and reading using the shared memory is high, then it would be very complex to implement the functionality. If we want to communicate with small message formats. Whereas in shared memory, the data is available for multiple processes to access. Why do we need message queues when we already have the shared memory? It would be for multiple reasons, let us try to break this into multiple points for simplification −Īs understood, once the message is received by a process it would be no longer available for any other process.
