You are on page 1of 14

Lecture 14

By
Dr. Aditya Bhardwaj

aditya.bhardwaj@bennett.edu.in

IPC (Interprocess Communication)


SYLLABUS
 Module 2 (Contact hours: 8)

 Process Synchronization, Critical section problem (CSP), Synchronization


constructs, Hardware solutions to CSP – Lock variables, Software solutions to CSP –
Peterson solutions, strict alteration, Classical synchronization problem, Producer
consumer problem, Dining philosopher problem, Reader writer problem, Monitor,
Deadlock, Necessary condition for deadlock, Deadlock prevention, Deadlock
avoidance (Banker’s algorithm), Deadlock detection, Resource allocation graph,
Deadlock recovery.
SYLLABUS (CONTD..)
FUNCTIONALITY OF OS

Functionality of OS

Process Memory I/O File


Security
Management Management Management Management
HOW SYLLABUS COULD BE DESIGNED?
How to Optimize CPU Utilization? When two processes are sharing
Module 1: the common resources:
1.1. Introduction to OS Module 2:
1.2 CPU Scheduling 2.1. Interprocess communication
2.2. Deadlock

How to manage RAM and hard disk?


Module 3:
3.1. Memory Management
3.2. Hard disk Management
INTER PROCESS COMMUNICATION (IPC)

Definition: Interprocess communication is the mechanism provided by the


operating system that allows cooperating processes to communicate and
synchronize with each other.

Popular Purpose:
Mobile and device OSs enable different apps to communicate with each other.
Synchronization mechanisms are used to ensure that data exchanged between
apps is properly protected and that one app doesn't interfere with the operation
of another.
Suppose you have a shared printer connected to multiple computers in an
office. To avoid any conflicts, the operating system implements
synchronization techniques to regulate access to the printer. Here's how it
works:
 When a user sends a print job, the operating system places the job in a
queue.
PRINTER CASE  The operating system then checks if the printer is available. If it is, the
STUDY REAL-TIME first job in the queue is sent to the printer for printing.
EXAMPLE OF  While the first job is being printed, other users can send their print jobs
to the queue, but they cannot access the printer until the first job is
SYNCHRONIZATION finished.
IN OPERATING  Once the first job is finished, the next job in the queue is sent to the
SYSTEMS: printer, and the process continues.
 This example demonstrates the use of synchronization in operating
systems through the use of a queue, which regulates access to the shared
resource (the printer) and ensures that only one job is processed at a
time.
PHONE?

To Manage Execution of Multiple Apps: Mobile operating systems support multitasking,


allowing multiple apps to run simultaneously. Synchronization mechanisms are used to
manage the execution of these apps, ensuring that they take turns using the CPU and other
system resources. This prevents apps from freezing or crashing due to resource conflicts.

To Regulate Device Access: Multiple apps may need access to hardware devices like
cameras, sensors, or storage. Synchronization mechanisms help coordinate and manage
access to these resources to prevent conflicts and ensure that only one app can use a
particular device at a time.
ACCESS TO HARDDISK- EXAMPLE OF SYNCHRONIZATION IN OS:

Synchronization is also used in operating systems to regulate access to shared resources such as hard disks.

Suppose you have a multi-threaded system where multiple threads are trying to access the same hard disk to read and
write data. To prevent data corruption and other synchronization issues, the operating system implements
synchronization techniques to regulate access to the hard disk

 When a thread wants to access the hard disk to read or write data, it requests the operating system for access.

 The operating system checks if the hard disk is available. If it is, the thread is granted access to the hard disk, and it
can read or write data as needed.
 While one thread is accessing the hard disk, other threads are prevented from accessing the hard disk. They must wait
until the first thread finishes and releases the hard disk.
 Once the first thread finishes its access to the hard disk, the next thread in the queue can access the hard disk, and the
process continues.

This example demonstrates the use of synchronization in operating systems to regulate access to shared resources such as
hard disks. By implementing this mechanism, the operating system ensures that multiple threads can access the hard disk
in a controlled and predictable manner, preventing data corruption and other synchronization issues.
WHY WE NEED IPC?

There are numerous reasons to use inter-process communication for sharing the data. Here
are some of the most important reasons that are given below:
1. Information sharing: Many processes will be interested in the same piece of
information(a shared file or a library).
2. Computational speedup: We cab break a task into subtasks and let each subtask run on
a separate processor. These tasks can then use IPC for exchanging information. This
makes the program run fast.
3. Modularity: A program can be divided into multiple chunks of code each performing a
specific function. Maintaining and debugging the code will then be easy.
4. Convenience: Even an individual user may work on many tasks at the same time. For
instance, a user may be editing, listening to music, and compiling in parallel.
VARIOUS SOLUTIONS FOR SYNCHRONIZATION: S

1 Software Type Solution


a. Lock variable
b. Strict alterations
c. Interested variable mechanism
d. Petersons solutions

2 Hardware type solution


e. TSL instruction set

3 Operating System Type Solutions


Binary semaphore
Counting semaphore
Mutex (A special binary semaphore)
OS Type Interprocess Synchronization Technique
Window Mutex, Semaphore
Linux, Mac OS Mutex, Semaphore, SpinLock,
Thank
You

You might also like