Cooperating Processes
Cooperating Processes
Principles of Operating
System
Course Code CIT11
• Interprocess Communication
Objectives
Interprocess Communication
• Processes within a system may be independent or
cooperating
• Cooperating process can affect or be affected by other
processes, including sharing data
• Reasons for cooperating processes:
• Information sharing
• Computation speedup
• Modularity
• Convenience
• Cooperating processes need interprocess communication
(IPC)
• Two models of IPC
• Shared memory
Wedad Al-Sorori 14 September 2017 Introduction 4/51
CIT11: Principles of Operating System
Communications Models
(a) Message passing. (b) shared memory.
Producer-Consumer Problem
Direct Communication
• Processes must name each other explicitly:
• send (P, message) – send a message to process P
• receive(Q, message) – receive a message from process Q
Indirect Communication
• Messages are directed and received from mailboxes (also
referred to as ports)
• Each mailbox has a unique id
• Processes can communicate only if they share a mailbox
Indirect Communication
• Operations
• Create a new mailbox (port)
• Send and receive messages through mailbox
• Destroy a mailbox
• Primitives are defined as:
send(A, message) – send a message to mailbox A
receive(A, message) – receive a message from mailbox A
Indirect Communication
• Mailbox sharing
• P1, P2, and P3 share mailbox A
• P1, sends; P2 and P3 receive
• Who gets the message?
• Solutions
• Allow a link to be associated with at most two processes
• Allow only one process at a time to execute a receive operation
• Allow the system to select arbitrarily the receiver. Sender is
notified who the receiver was.
Synchronization
• Message passing may be either blocking or non-blocking
• Blocking is considered synchronous
• Blocking send -- the sender is blocked until the message is
received
• Blocking receive -- the receiver is blocked until a message is
available
• Non-blocking is considered asynchronous
• Non-blocking send -- the sender sends the message and continue
• Non-blocking receive -- the receiver receives:
A valid message, or
Null message
Different combinations possible
If both send and receive are blocking, we have a rendezvous
Wedad Al-Sorori 14 September 2017 Introduction 16/51
CIT11: Principles of Operating System
Buffering
• Queue of messages attached to the link.
• Sockets
• Pipes
Sockets
• A socket is defined as an endpoint for communication
• All ports below 1024 are well known, used for standard services
Socket Communication
Sockets in Java
• Three types of sockets
• Connection-oriented
(TCP)
• Connectionless (UDP)
• MulticastSocket class–
data can be sent to
multiple recipients
Execution of RPC
Pipes
• Acts as a conduit allowing two processes to communicate
• Issues:
• Is communication unidirectional or bidirectional?
• In the case of two-way communication, is it half or full-duplex?
• Must there exist a relationship (i.e., parent-child) between the
communicating processes?
• Can the pipes be used over a network?
• Ordinary pipes – cannot be accessed from outside the process
that created it. Typically, a parent process creates a pipe and
uses it to communicate with a child process that it created.
• Named pipes – can be accessed without a parent-child
relationship.
Ordinary Pipes
• Ordinary Pipes allow communication in standard producer-consumer
style
• Producer writes to one end (the write-end of the pipe)
• Consumer reads from the other end (the read-end of the pipe)
• Ordinary pipes are therefore unidirectional
• Require parent-child relationship between communicating processes
Named Pipes
• Named Pipes are more powerful than ordinary pipes
• Communication is bidirectional
• No parent-child relationship is necessary between the
communicating processes
• Several processes can use the named pipe for
communication
• Provided on both UNIX and Windows systems
Summary
Assignment
• Answer and submit questions in assignment8 that was attached
with this lecture on CLMS.
Thanks