OSLab: Module 5 - Interprocess Communication
Module 5 extends the kernel developed in Module 3 to support interprocess communication. A process can send a message to any other process using the send() primitive:
send(TO, MSG, SIZE)
where TO is the process identifier of the destination process, MSG is the message (up to 256 bytes in length), and SIZE are the number of bytes in the message. The kernel is responsible for placing the message on the queue associated with the destination process. Send() returns 0 if the message was 'sent' to the destination; should send() fail, a negative number is returned, indicating the reason for the failure (see MODULE5.H).
A process can read its queue using the receive() primitive:
receive(&FROM, &MSG, SIZE, TIMELIMIT)
where FROM is the process identifier of the sending process, MSG is the message sent by the sending process, SIZE is the maximum number of bytes that can be stored in MSG (if MSG contains more than SIZE bytes, the message is truncated and the data is lost), and TIMELIMIT is the number of seconds that the receiving process is willing to wait for a message (zero, 0, means an immediate poll, while a positive number indicates the number of seconds to wait; the constant INFINITE implies an indefinite wait). Receive() returns the number of bytes or, if it fails, a negative number, indicating the reason for failure (see MODULE5.H).
The kernel is extended to support interprocess communication; the instructions to handle IPC are found in MSGMGMT.C. Send() and receive() are implemented in two locations: the call to the kernel is in IPC.C, while the actual enqueuing and dequeuing of messages is performed in MSGMGMT.C.
A version of the producer-consumer problem is supplied in Module 5.
The .H (header) files contain data structures required for this module. The .C files contain the source code for: