You are on page 1of 8

y Chapter 4 y Message Passing

Message Passing
Process Pi
..

Process Pj
. Receive (Pi,<area address>);

send (Pj, <message>);


.

Shows message passing between processes Pi and Pj. Process Pi sends a massage msgk to process Pj by executing a function call send (Pj,msgk) which leads to system call send. The kernel has to ensure that the message msgk reaches Process Pj when it wishes to receive message, I.e. when it executes system call receive.
2

November 17, 2011

y y Issues of message passing

Issues of message passing


Issue
Naming of processes Method for transferring messages

Aspect
Processes participating in message transfer are explicitly indicated or deduced by the kernel Whether a sender process is blocked until a message sent by it is delivered, the order in which messages are delivered etc

Kernel Buffering of messages pending delivery to responsibilities recipient processes. Blocking and activation of processes.
November 17, 2011 3

y y Direct and Indirect naming y Send and receive statements shown below use direct naming. y Sender and receiver processes mention each others name using the following syntax (Symmetric naming)

y Send(<destination_ process>, <message>); y Receive (<source_process>, <message_area>); y The send and receive statements using asymmetric naming have the following syntax. y Send(<destination_ process>, <message>); y Receive (<message_area>); y In indirect naming, processes do not mention each others names in send and receive statements. y Blocking and Non-blocking sends y y The send primitive has two variants. y A blocking send blocks a sender process till the message being sent is delivered to the destination. y A non blocking send permits a sender to continue execution after executing a send irrespective of message being delivered immediately. y Receive primitive is typically blocking. y Process performing a receive must wait until a message can be delivered to it. y Message passing using blocking and non blocking sends are known as synchronous and asynchronous message passing respectively.

y Blocking and Non-blocking sends y Consider a process Pi with the following text:  Send (Pj , ..);  .  Send (Pk , ..); y If a blocking send is used, process Pi would be blocked on the first send until process Pj executes a matching receive statement. y Thus progress would depend upon when processes Pj and Pk perform their receives. y If a non-blocking send is used Pi can make progress independent of Pj and Pk. y However kernel must buffer its message until they are delivered. y Exceptional conditions o Several exceptional conditions can arise during message delivery

y The destination process mentioned in a send does not exist. y A send cannot be executed because the kernel has run out of buffer memory. y No message exits for a process when it executes a receive statement. y Implementing Message Passing  Interprocess message Control block (IMCB) 

Implementing Message Passing


Interprocess message Control block (IMCB)
IMCB Pointer Sender Process Destination Process Message length Message text of address

November 17, 2011

y y Implementing Message Passing y When a process Pi sends a message to some process Pj using a non-blocking send, the kernel builds an IMCB to store all information needed to deliver the message. y The control block contains names of sender and destination processes, length of the message and the text of the message. y The control block is allocated a buffer in the kernel area and the buffer is entered into an appropriate list using the IMCB pointer field. y When process Pj executes a receive call, the kernel copies the message from the appropriate IMCB into the message area provided by Pj. y Delivery of Interprocess Messages y Two possibilities arise when a process Pi sends a message to process Pj: y Process Pi has already performed a receive and is in the blocked state.

y Process Pj has not performed a receive but may perform it sometime in future. y In former case, the kernel must arrange to deliver the message to Pj straightaway. y In the latter case, the kernel must deliver the message when Pj performs a matching receive. y Delivery of Interprocess Messages y Message delivery actions of the kernel are triggered by send and receive events, so they can be implemented using event control blocks (ECBs). y An ECB is created for an event when some process decides to wait for its occurrence. y An ECB contains three fields: y Description of an anticipated event y ID of the process that awaits this event. y An ECB pointer for forming ECB lists. y ECBs in symmetric naming and blocking sends (a) at send, (b) at receive y Kernel actions in message passing using symmetric naming and blocking sends y At send to Pj by Pi: y S1 Create an IMCB and initialize its fields; y S2 If an ECB for a send to Pj by Pi event exits y S3 then y Deliver the message to Pj y Activate Pj y Destroy the ECB and IMCB y Return to Pi y S4 else y Create an ECB for a receive from Pi to Pj event and put id of Pi as the process awaiting the event; y Change the state of Pi to blocked and put the ECB address in Pis PCB y Add the IMCB to Pjs IMCB list y Kernel actions in message passing using symmetric naming and blocking sends y At receive from Pi by Pj:

y y y y y y y y

R1 If a matching ECB for a receive from Pi by Pj event exits R2 then Deliver the message from appropriate IMCB in Pjs list Activate Pi Destroy the ECB and IMCB Return to Pj R3 else Create an ECB for a send to Pj by Pi event and put id of Pj as the process awaiting the event; y Change the state of Pj to blocked and put the ECB address in Pjs PCB y y y y y y Mailboxes A mailbox is a repository for interprocess messages. It has its own identity. The owner of a mailbox is typically a process that created it. Only the owner process can receive messages from a mailbox. Any process that knows the identity of a mailbox can send messages to it.

y A mailbox y y y y y y y y y y A mailbox Illustrates message passing using a mailbox named sample. Process Pi creates the mailbox using the call create_mailbox. Process Pj sends a message to the mailbox using the mailbox name instead of a process id in its send call. This is an instance of indirect naming. A message sent to sample is stored in the buffer. It is delivered to process Pi when Pi performs a receive on sample. Some other processes Pk and Pl might also send messages to sample Advantages of mailbox Anonymity of the receiver: A process sending a message to a mailbox need not know the identity of the receiver process.

y Classification of messages: A process may create several mailboxes and use each mailbox to receive messages of a specific kind. This arrangement provides easy classification of messages. y Message Passing in UNIX y Unix system V release 4 (Unix SVR4) supports three interprocess message communication facilities- pipes, message queues and sockets. y A pipe is a general purpose communication facility while message queues and sockets are used for message passing. y Interprocess communication in Unix  (a) Pipe (b) Message Queue (c) Socket y Interprocess communication in Unix y Pipes: A pipe is a FIFO mechanism for date transfer between the processes. y Message Passing: y The concept of a message queue is analogous to the concept of a mailbox. y A message queue is created and owned by one process. y A message queue is created by a msgget call msgget (key,flag) where key specifies the name of the message queue and flag indicates some options. y The messages are sent and received using msgsnd and msgrcv calls. y Interprocess communication in Unix y Sockets: y A socket is simply one end of a communication path. y It can be used for interprocess communication within Unix system domain and in the internet domain. y Process are either clients or servers. y Both client and Server process create a socket each. y These two sockets are connected to set up a communication path. y Message passing in Windows y Windows provides local procedure call (LPC) facility for message passing between processes located in the same computer system. y Remote procedure call (RPC) in distributed environment.

y LPC provides a choice of three types of message passing to suit passing of small messages, large messages and special messages. y Message passing in Windows y For small messages, the message queue contains a text of message upto 304 bytes in length. y Messages get copied twice during message passing, first copied to the message queue of the port and then to the address space of the receiver. y Large messages are put to section object which are mapped to address space of the processes. y The third type of LPC provides fast method of message passing hence called quick LPC. y y y y y y y y y y y y y y y Chapter 5 Scheduling Preliminaries Scheduling policy used in OS influences user service, efficient use of resources and system performance. Scheduling is the activity of selecting the next request to be serviced by the server. A scheduling policy determines the quality of service provided to the user. Scheduling concepts and terminology Scheduling concepts and terminology Whenever scheduling is to be performed, the scheduler examines the pending requests and selects one for servicing. A request leaves the server when it completes or when it is preempted by the scheduler. Four events related to scheduling are arrival, scheduling, preemption and completion. Scheduling-related Concepts and Terms Kinds of Scheduling Non-preemptive scheduling: A process runs to completion when scheduled Preemptive scheduling: A process may be preempted by the kernel, and another process may be scheduled. Hence a set of processes are processed in an overlapped manner.

y Non-preemptive scheduling Process for Scheduling y Scheduling using FCFS and SRN (Shortest Request Next)

You might also like