Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 25

Inter-Process

Communication
Members Name

• Ayesha Taimoor(014)
• Javeria Bibi(001)
• Sidra Bibi(006)
• Anisa Bibi(021)
• Tanzila Javeed(005)
• Zainab Asghar(058)

3
A
Agenda
Introduction

Why we use IPC

Types/Ways of IPC

Shared Memory

Procedure-Consumer
problem

Message Passing system


4
IPC
Inter process communication (IPC) is used for exchanging data
between multiple threads in one or more processes or programs.
The Processes may be running on single or multiple computers
connected by a network.
The full form of IPC is Inter-process communication.

5
Approaches
Here, are few important methods for
interprocess communication:
Pipes
Message Passing
Message Queues
Direct Communication
Indirect Communication
Shared Memory
FIFO

6
Why We Use IPC
Information sharing: Several processes may need to
access the same data(such as stored in a file)
Computation speedup: A task can offer be run faster if
it is broken into subtasks and distributed among
different processes
Resource Sharing: Sharing Hardware, memory etc.
Why We Use IPC
Modularity: It may be easier to organize a complex
task into separate subtasks, then have different
processes or threads running each subtasks.
Convenience: An individual user can run several
programs at the same time, to perform some task

8
Types/Ways of IPC
• Shared Memory systems
• Message Passing systems

9
Cooperating Processes
• Independent process cannot affect or be affected by the execution of
another process
• Cooperating process can affect or be affected by the execution of another
process
• Advantages of process cooperation
• Information sharing
• Computation speed-up
• Modularity
• Convenience

10
Shared Memory
• Allows multiple processes to share virtual memory space
• Fastest but not necessarily the easiest (synchronization-wise) way for
processes to communicate with one another
Shared Memory

12
Producer-Consumer
problem

• There are two processes: Producer and Consumer


• Producer produces some item and Consumer consumes that
item.
• The two processes shares a common space or memory
location known as buffer where the item produced by
producer is stored and from where the Consumer consumes
the item if needed
Unbounded Buffer Problem

• There are two version of this problem: first one is


known as unbounded buffer problem in which
Producer can keep on producing items and there is no
limit on size of buffer problem in which producer can
produce up to certain amount of item and after that it
starts waiting for customer to consume it. The pseudo
code are given below: 14
Bounded Buffer Problem

• We will discuss the bounded buffer problem. First, the Producer and
the Consumer will share some common memory, then producer will
share some common memory, then producer will start producing items
.If the total produced item is equal to the size buffer, producer will
wait to get it consumed by the consumer. Similarly, the consumer first
check for the availability of the item and if no item is available,
Consumer will wait for producer to produce it. If there are items
available, consumer will consume it.
15
Producer Consumer problem

• { int item c; void producer(void)


• While(true) {
• { int itemp;
• While(count==0); while(true)
• Item c=Buffer(out){
• Out=(out+1)mod n; produce. Item(itemp);
• Count=count-1; while(count==n);
• Process. Item(items); Buffer[int]=itemp;
• } in=(in+1)mod n;
• } count=count+1;}
}
16
Message-Passing systems

• In a Message passing system there are no shared variables


• IPC facility provides two operations for fixed or variable sized
message
• Send(message)
• Receive(message)
• If processes P and Q wish to communicate, they need to:
• Establish a communication link
• Exchange messages via send and receive
17
18
Key issue

• There are the key issues to be resolved in message


passing systems as further explored in the next
subsections:
• Direct or indirect communication(naming)
• Synchronous or asynchronous communication

19
Direct Communication

• With direct communication the sender must know the name of the
receiver to which it wishes to send a message. There is a one-to-one
link between every sender-receiver pair
• Symmetric communication, the receiver must also know the specific
name of the sender from which it wishes to receive messages.
• Asymmetric communications, this is not necessary

20
Indirect Communication

• Indirect communication uses shared mailboxes, or ports. Multiple


processes can share the same mailbox or boxes.
• Only one process can read any given message in a mailbox. Initially
the process that creates the mailbox is the owner, and is the only one
allowed to read mail in the mailbox, although this privilege may be
transferred
• The OS must provide system calls to create and delete mailboxes, and
to send and receive messages to/from mailboxes
21
Synchronous

• Synchronous messaging involves a client that waits for the server to


respond to a message. Messages can flow in both directions, to and
from.

22
Asynchronous Communication

• Asynchronous messaging involves a client that does not wait for a


message from the server. An event is used to trigger a message from a
server. So even if the client is down, the messaging will complete
successfully. Asynchronous Messaging means that, it is a one-way
communication, and the flow of communication is one way only.

23
Summary

Definition: Inter-process communication is used for exchanging data between multiple threads


in one or more processes or programs
Message passing is a mechanism for a process to communicate and synchronize
• Direct process is a type of inter-process communication process, should name each other
explicitly.
• Indirect communication establishes like only when processes share a common mailbox each
pair of processes sharing several communication links.
• Shared memory is a memory shared between two or more processes that are established
using shared memory between all the processes.
• Inter Process Communication method helps to speedup modularity.
24
Thank you

You might also like