Professional Documents
Culture Documents
10EC65
Unit 8
Message Passing
Reference Book:
Operating Systems - A Concept based Approach
D. M. Dhamdhare, TMH, 3rd Edition, 2010
Shrishail Bhat, AITM Bhatkal
Overview of Message Passing
Message passing is one way in which processes interact with one another
In cases 1 and 2, the kernel may abort the process that made the
send or receive call and set its termination code to describe the
exceptional condition
In case 3, the sender process may be blocked until some buffer
space becomes available
In case 4, a process may prefer the standard action, which is that
the kernel should block the process until a message arrives for it, or
it may prefer an action of its own choice, like waiting for a specified
amount of time before giving up
The deadlock situation of case 5 is an example of a severe
exception. Most operating systems do not handle this particular
exception because it incurs the overhead of deadlock detection
Shrishail Bhat, AITM Bhatkal
Implementing Message Passing
The kernel uses an event control block (ECB) to note actions that
should be performed when an anticipated event occurs
At a send call, the kernel creates an IMCB even though a sender process is
blocked until message delivery
When process sends a message to process , the kernel first checks
whether the send was anticipated, i.e., whether an ECB was created for the
send event
It will have happened if process has already made a receive call for a
message from
If this is the case, action S3 immediately delivers the message to and
changes its state from blocked to ready
The ECB and the IMCB are now destroyed
If an ECB for send does not exist, step S4 creates an ECB for a receive call by
process , which is now anticipated, blocks the sender process, and
enters the IMCB in the IMCB list of process
Shrishail Bhat, AITM Bhatkal
Kernel Actions in Message Passing (continued)
When data is written, it is entered into the pipe by using the write
offset, and the write offset is incremented by the number of bytes
written
Data written by multiple writers gets mixed up if their writes are
interleaved
If a pipe is full, a process wishing to write data into it would be put
to sleep
A read operation is performed by using the read offset, and the
read offset is incremented by the number of bytes read
A process reading data from a pipe would be put to sleep if the
pipe is empty
Analogous to a mailbox
Created and owned by one process
Creator specifies access permissions for send/receive
Size specified at the time of its creation
A message queue is created by a system call msgget (key, flag)
where key specifies the name of the message queue and flag
indicates some options
Each message consists of a message type, in the form of an integer,
and a message text
The server process now makes a call bind (s, addr, . . . ), which
binds the socket to the address addr
The server performs the system call listen (s, . . . ) to indicate that it
is interested in considering some connect calls to its socket s
A client creates a socket by means of a socket call, e.g.,
cs = socket (. . .), and attempts to connect it to a servers socket
using the system call
connect (cs, server_socket_addr, server_socket_addrlen)
The kernel now creates a new socket with the call
new_soc = accept (s, client_addr, client_addrlen)
The server uses this socket to implement the client server
communication
Shrishail Bhat, AITM Bhatkal
Message Passing in Unix: Sockets (continued)
Typically, after the connect call the server forks a new process to
handle the new connection
Leaves the original socket created by the server process free to accept
more connections through listen and connect calls
Communication between a client and a server is implemented
through read and write or send and receive calls.
A send call has the format
count = send (s, message, message_length, flags)
A socket connection is closed by using the call close (s) or
shutdown (s, mode)
Sockets use indirect naming: address (domain) used instead of
process ids
Shrishail Bhat, AITM Bhatkal