Lec 14 IPC, Message Passing
Lec 14 IPC, Message Passing
By
Dr. Aditya Bhardwaj
Functionality of OS
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 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