Interprocess Communication
Interprocess Communication
Communication
Module 2
Interprocess Communication
• The way in which processes communicate with each other
• Now, processes executing concurrently in the operating system may be
either independent processes or cooperating processes.
• Independent processes – they cannot affect or be affected by the
other processes executing in the system
• Cooperating processes – they can affect or be affected by the other
processes executing in the system
• Any processes that shares data with other processes is a cooperating
processes
Several Reasons for providing an environment that allow process cooperation:
Ms.U.Elakkiya AP/IT 6
Shared memory
• IPC using shared memory requires to establish a region of shared
memory
• Shared-memory resides in the address space of the process creating
the memory segment
• If other process wants to communicate the shared-memory segment
must attach their address space
• OS to prevent one process from accessing another process memory
• Process also responsible for ensure that they not to write on same
location
Producer-Consumer Problem
• To illustrate the concept of cooperating process, let us
consider the producer – consumer problem
• Producer – to produce information
• Consumer – to consume
• Example : web server provides the web pages (HTML
files and images) which is consumed by client(web
browser) requesting resource
• One solution for producer – consumer problem uses shared
memory
• It allows the producer and consumer process to run
concurrently we need available a buffer of items that filled
by producer and empty by consumer
Ms.U.Elakkiya AP/IT 8
Contd..
• This buffer will reside in a region of memory that
is shared by producer and consumer process
• Producer produce one item while consumer
consume another item
• Both will be synchronized
• Consumer does not try to consume an item that has
not produced
• Two types of buffer has used.
• Bounded buffer
• Unbounded buffer
Ms.U.Elakkiya AP/IT 9
Contd..
unbounded-buffer places no practical limit on the
size of the buffer
In this, the consumer may have to wait for new
items but the producer can always produce new
items
bounded-buffer assumes that there is a fixed
buffer size
In this the consumer must wait if the buffer is
empty and the producer must wait if the buffer is
full
Ms.U.Elakkiya AP/IT 10
C Program-shared memory
int shmid = shmget(key, SHM_SIZE, 0666 | IPC_CREAT); //Create shared memory