IPC - Message Queues - Jeremy

From MMAE

Jump to: navigation, search

Message Queues

[edit] General Message Structure

struct msg {
     struct msg     *msg_next;    /* ptr to next message */
     long            msg_type;    /* message type */
     ushort          msg_ts;      /* message text size */
     short           msg_spot;    /* address to text message*/
};

Note: The long msg_type and be used as an identifier for which process to pick up that message.

[edit] General Life Cycle:

A process generates a message and places it in a system maintained message queue. Processes access the queue and use the message type to selectively read messages of a specific type in a FIFO manner. Message Queues provide a means of "asynchronously multiplexing data from multiple processes".

Placing info in a message stucture
Pass the IPC identifier of the IPC message queue resource
Pass the size of the message
Pass the address to the message text (This is stored in a User Mode buffer that contains the message type followed by the message text).
Retreiving info from a message structure [using msgrcv()]
Accepts the IPC identifier of the IPC message queue resource
Accepts the pointer to the buffer where the message type and text should be copied.
Accepts the size of the buffer.
Accepts the value t which is what message should be recieved.

t = NULL, first message in the queue is retrieved
t > 0, first message in the queue with type t is retrieved
t < 0, retrieves the message with the lowest type <= |t|

[edit] Summary

  • IPC-Message Queues can be addressed to processes.
  • They do not currently have a priority handling system (They are FIFO) unless it is incorporated into the type.
  • "Can be used by related and unrelated processes, but these processes must be on the same system (machine)."
  • The length of the message text cannot exceed MSGMAX, usually 4056 bytes.
  • The total size of all the header and text of all messageues in the queues cannot exceed msg_qbytes; default of MSGMNB = 16,384 bytes.
Personal tools