SlideShare una empresa de Scribd logo
1 de 31
Inter Process
Communication (IPC)
Introduction - IPC
• Since processes frequently need to communicate with other processes
therefore, there is a need for a well-structured communication, without
using interrupts, among processes.
• Processes within a system may be independent or cooperating
• Cooperating processes can affect or be affected by other processes,
including sharing data.
• Cooperating processes need inter-process communication (IPC)
• Inter processor communication in a multiprocessor system─ used to
generate information about certain sets of computations finishing on one
processor and to let the other processors waiting for finishing the
computations take note of the information
• Similarly, there is inter process communication from a process (task or
thread to another)
IPC Ctd’
• Reasons for cooperating processes:
- Information sharing
- Computation speedup
- Modularity
- Convenience
• In IPC, it means that a process (scheduler, task or ISR) generates some
information by signal (for other process start) or value (for example of
semaphore) or generates an output so that it lets another process
take note or use it through the kernel functions for the IPCs
Objectives
• To cover the following sections:
• Critical Section
• Mutual Exclusion
• Achieving Mutual Exclusion
• Semaphores
IPC
• 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
• Two models of IPC
• Shared memory
• Message passing
communication models
a) Message passing
Communication models
b) Shared memory
Message Passing
• Mechanism for process to communicate and synchronize their actions
• Message system process communicate with each other without resorting to shared
variables
• IPC facility provides two operations:
• Send(message) –message size fixed or variable
• Receive(message)
• If P and Q wish to communicate, they need to:
Establish a communication link between them
Exchange messages via send/receive
• Implementation of communication link
Physical (e.g shared memory ], hardware bus)
Logical( e.g direct or indirect, synchronous or asynchronous)
Message Passing
• Implementation questions
• How are links established?
• Can a link be associated with more than two processes?
• How many links can there be between every pair of communicating
processes?
• What is the capacity of a link?
• Is the size of a message that the link can accommodate fixed or
variable?
• Is a link unidirectional or bi-directional?
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
• Properties of direct communication link
• A link is associated with exactly one pair of communicating processes
• Between each pair there exists exactly one link
• The link may be unidirectional, but is usually bi-directional
Indirect Communication
• Messages are directed and received mailboxes(also referred to as
ports)
• Each mailbox has a unique id
• Processes can communicate only if they share a mailbox
• Properties of communication link
Link established only if processes share a common mailbox
A link may be associated with many processes
Each pair of processes may share several communication links
Link may be unidirectional or bi-directional
Message Passing
Mechanisms
• Transfer data/info between address spaces
• Maintain protection and isolation
• Provide flexibility and performance
• Processess
Write(send) and read(receive)
Advantage is that OS manages
Disadvantage is overheads
Shared memory IPC
Shared memory IPC
• OS establishes shared channel and maps it into each process address
space
• Processes directly read/write from this memory
• OS is out of the way
Race Conditions
• In operating systems, processes that are working together share some
common storage (main memory, file etc.) that each process can read and
write.
• When two or more processes are reading or writing some shared data and the
final result depends on who runs precisely when, are called race conditions.
• Concurrently executing threads that share data need to synchronize their
operations and processing in order to avoid race condition on shared data.
• Only one ‘customer’ thread at a time should be allowed to examine and
update the shared variable.
• Race conditions are also possible in Operating Systems.
• If the ready queue is implemented as a linked list and if the ready queue is
being manipulated during the handling of an interrupt, then interrupts must
be disabled to prevent another interrupt before the first one completes.
• If interrupts are not disabled then the linked list could become corrupt.
Critical Section
• The key to preventing trouble involving shared storage is find some way
to prohibit more than one process from reading and writing the shared
data simultaneously.
• That part of the program where the shared memory is accessed is called
the Critical Section.
• To avoid race conditions and flawed results, one must identify codes in
Critical Sections in each thread.
• The characteristic properties of the code that form a Critical Section are
Codes that reference one or more variables in a “read-update-write”
fashion while any of those variables is possibly being altered by another
thread.
Codes that alter one or more variables that are possibly being referenced
in “read-update-write” fashion by another thread.
Codes use a data structure while any part of it is possibly being altered by
another thread.
Codes alter any part of a data structure while it is possibly in use by
another thread.
• Here, the important point is that when one process is executing shared
modifiable data in its critical section, no other process is to be allowed to
execute in its critical section.
• Thus, the execution of critical sections by the processes is mutually
exclusive in time.
Mutual Exclusion
• A way of making sure that if one process is using a shared modifiable data,
the other processes will be excluded from doing the same thing.
• Formally, while one process executes the shared variable, all other processes
desiring to do so at the same time moment should be kept waiting; when
that process has finished executing the shared variable, one of the processes
waiting; while that process has finished executing the shared variable, one of
the processes waiting to do so should be allowed to proceed.
• In this fashion, each process executing the shared data (variables) excludes
all others from doing so simultaneously. This is called Mutual Exclusion.
• Note that mutual exclusion needs to be enforced only when processes
access shared modifiable data - when processes are performing operations
that do not conflict with one another they should be allowed to proceed
concurrently.
Mutual Exclusion Conditions
• If we could arrange matters such that no two processes were ever in their
critical sections simultaneously, we could avoid race conditions.
• We need four conditions to hold to have a good solution for the critical
section problem (mutual exclusion).
i. No two processes may at the same moment inside their critical sections.
ii. No assumptions are made about relative speeds of processes or number
of CPUs.
iii. No process, outside its critical section, should block other processes.
iv. No process should wait arbitrary long to enter its critical section.
Proposals for Achieving Mutual Exclusion
• The mutual exclusion problem is to devise a pre-protocol (or entry
protocol) and a post-protocol (or exist protocol) to keep two or more
threads from being in their critical sections at the same time.
• Tanenbaum examine proposals for critical-section problem or mutual
exclusion problem.
Problem
• When one process is updating shared modifiable data in its critical
section, no other process should allowed to enter in its critical
section.
Proposal 1 -Disabling Interrupts (Hardware Solution)
• Each process disables all interrupts just after entering in its critical
section and re-enable all interrupts just before leaving critical section.
• With interrupts turned off the CPU could not be switched to other
process.
• Hence, no other process will enter its critical and mutual exclusion
achieved.
Conclusion
• Disabling interrupts is sometimes a useful technique within the kernel
of an operating system, but it is not appropriate as a general mutual
exclusion mechanism for users process.
• The reason is that it is unwise to give user process the power to turn off
interrupts.
Proposal 2 - Lock Variable (Software Solution)
• In this solution, we consider a single, shared, (lock) variable, initially 0.
• When a process wants to enter in its critical section, it first test the lock.
• If lock is 0, the process first sets it to 1 and then enters the critical section.
• If the lock is already 1, the process just waits until (lock) variable becomes
0.
• Thus, a 0 means that no process in its critical section, and 1 means hold
your horses - some process is in its critical section.
Conclusion
• The flaw in this proposal can be best explained by example.
• Suppose process A sees that the lock is 0.
• Before it can set the lock to 1 another process B is scheduled, runs, and
sets the lock to 1.
• When the process A runs again, it will also set the lock to 1, and two
processes will be in their critical section simultaneously.
Proposal 3 - Strict Alteration
• In this proposed solution, the integer variable 'turn' keeps track of whose
turn is to enter the critical section.
• Initially, process A inspect turn, finds it to be 0, and enters in its critical
section.
• Process B also finds it to be 0 and sits in a loop continually testing 'turn' to
see when it becomes 1.
• Continuously testing a variable waiting for some value to appear is called
the Busy-Waiting.
Conclusion
• Taking turns is not a good idea when one of the processes is much slower
than the other.
• Suppose process 0 finishes its critical section quickly, so both processes are
now in their non-critical section.
• This situation violates above mentioned condition 3.
Using Systems calls 'sleep' and 'wakeup'
• Basically, what above mentioned solution do is this: when a processes wants
to enter in its critical section , it checks to see if the entry is allowed.
• If it is not, the process goes into tight loop and waits (i.e., start busy waiting)
until it is allowed to enter. This approach waste CPU-time.
• Now looking at some inter-process communication primitives: is the pair of
sleep-wakeup.
Sleep
• It is a system call that causes the caller to block, that is, be suspended until some other
process wakes it up.
Wakeup
• It is a system call that wakes up the process.
• Both 'sleep' and 'wakeup' system calls have one parameter that represents a
memory address used to match up 'sleeps' and 'wakeups' .
Producer-Consumer Problem
• Producer-consumer problem is a common paradigm for cooperating processes
• Producer process produces information that is consumed by a consumer
process
- One solution is to use shared memory for the two processes to
communicate
- Useful to have a buffer that can be filled by the producer and
emptied by the consumer if they are to run concurrently
• Unbounded-buffer places no practical limit on the size of
the buffer
• Bounded-buffer assumes that there is a fixed buffer size
• The bounded buffer producers and consumers assumes that there is a fixed
buffer size i.e., a finite numbers of slots are available.
The Bounded Buffer Producers and Consumers
Statement
To suspend the producers when the buffer is full, to suspend the consumers when the buffer is empty, and to
make sure that only one process at a time manipulates a buffer so there are no race conditions or lost
updates.
• As an example how sleep-wakeup system calls are used, consider the producer-consumer problem also
known as bounded buffer problem.
• Two processes share a common, fixed-size (bounded) buffer. The producer puts information into the buffer
and the consumer takes information out.
• Trouble arises when
i. The producer wants to put a new data in the buffer, but buffer is already full.
Solution: Producer goes to sleep and to be awakened when the consumer has removed data.
ii. The consumer wants to remove data the buffer but buffer is already empty.
Solution: Consumer goes to sleep until the producer puts some data in buffer and wakes consumer up.
Conclusion
• This approaches also leads to same race conditions we have seen in earlier approaches.
• Race condition can occur due to the fact that access to 'count' is unconstrained.
• The essence of the problem is that a wakeup call, sent to a process that is not sleeping, is lost.
Semaphores
• E.W. Dijkstra (1965) abstracted the key notion of mutual exclusion in his
concepts of semaphores.
• Definition
A semaphore is a protected variable whose value can be accessed and altered
only by the operations P and V and initialization operation called
'Semaphoiinitislize'.
• Binary Semaphores can assume only the value 0 or the value 1 counting
semaphores also called general semaphores can assume only nonnegative
values.
• The P (or wait or sleep or down) operation on semaphores S, written as P(S)
or wait (S), operates as follows:
• P(S): IF S > 0
THENS := S - 1
ELSE (wait on S)
• The V (or signal or wakeup or up) operation on semaphore S, written as
V(S) or signal (S), operates as follows:
• V(S): IF (one or more process are waiting on S)
THEN (let one of these processes proceed)
ELSE S := S +1
• Operations P and V are done as single, indivisible, atomic action.
• It is guaranteed that once a semaphore operations has stared, no other
process can access the semaphore until operation has completed.
• Mutual exclusion on the semaphore, S, is enforced within P(S) and V(S).
• If several processes attempt a P(S) simultaneously, only process will be
allowed to proceed. T
• he other processes will be kept waiting, but the implementation of P and
V guarantees that processes will not suffer indefinite postponement.
• Semaphores solve the lost-wakeup problem.
Producer-Consumer Problem Using Semaphores
• The Solution to producer-consumer problem uses three semaphores, namely, full,
empty and mutex.
• The semaphore 'full' is used for counting the number of slots in the buffer that
are full.
• The 'empty' for counting the number of slots that are empty and semaphore
'mutex' to make sure that the producer and consumer do not access modifiable
shared section of the buffer simultaneously.
• Initialization
 Set full buffer slots to 0. (i.e., semaphore Full = 0.)
 Set empty buffer slots to N. (i.e., semaphore empty = N.)
 For control access to critical section set mutex to 1. (i.e., semaphore mutex = 1.)
Producer-Consumer Problem Using Semaphores
• Producer ( )
WHILE (true)
produce-Item ( );
P (empty);
P (mutex);
enter-Item ( )
V (mutex)
V (full);
• Consumer ( )
WHILE (true)
P (full)
P (mutex);
remove-Item ( );
V (mutex);
V (empty);
consume-Item (Item)

Más contenido relacionado

La actualidad más candente

Inter process communication
Inter process communicationInter process communication
Inter process communicationPradeep Kumar TS
 
Aggrement protocols
Aggrement protocolsAggrement protocols
Aggrement protocolsMayank Jain
 
Optimistic concurrency control in Distributed Systems
Optimistic concurrency control in Distributed SystemsOptimistic concurrency control in Distributed Systems
Optimistic concurrency control in Distributed Systemsmridul mishra
 
Distributed concurrency control
Distributed concurrency controlDistributed concurrency control
Distributed concurrency controlBinte fatima
 
Semophores and it's types
Semophores and it's typesSemophores and it's types
Semophores and it's typesNishant Joshi
 
Inter Process Communication
Inter Process CommunicationInter Process Communication
Inter Process CommunicationAdeel Rasheed
 
SYNCHRONIZATION IN MULTIPROCESSING
SYNCHRONIZATION IN MULTIPROCESSINGSYNCHRONIZATION IN MULTIPROCESSING
SYNCHRONIZATION IN MULTIPROCESSINGAparna Bhadran
 
OS - Process Concepts
OS - Process ConceptsOS - Process Concepts
OS - Process ConceptsMukesh Chinta
 
Operating System - Monitors (Presentation)
Operating System - Monitors (Presentation)Operating System - Monitors (Presentation)
Operating System - Monitors (Presentation)Experts Desk
 
Operating System Process Synchronization
Operating System Process SynchronizationOperating System Process Synchronization
Operating System Process SynchronizationHaziq Naeem
 
Inter Process Communication Presentation[1]
Inter Process Communication Presentation[1]Inter Process Communication Presentation[1]
Inter Process Communication Presentation[1]Ravindra Raju Kolahalam
 
Interprocess communication (IPC) IN O.S
Interprocess communication (IPC) IN O.SInterprocess communication (IPC) IN O.S
Interprocess communication (IPC) IN O.SHussain Ala'a Alkabi
 
Agreement Protocols, distributed File Systems, Distributed Shared Memory
Agreement Protocols, distributed File Systems, Distributed Shared MemoryAgreement Protocols, distributed File Systems, Distributed Shared Memory
Agreement Protocols, distributed File Systems, Distributed Shared MemorySHIKHA GAUTAM
 
Communication in Distributed Systems
Communication in Distributed SystemsCommunication in Distributed Systems
Communication in Distributed SystemsDilum Bandara
 
Cpu scheduling in operating System.
Cpu scheduling in operating System.Cpu scheduling in operating System.
Cpu scheduling in operating System.Ravi Kumar Patel
 
Multi processor scheduling
Multi  processor schedulingMulti  processor scheduling
Multi processor schedulingShashank Kapoor
 
Processes description and process control.
Processes description and process control.Processes description and process control.
Processes description and process control.Ahsan Rahim
 

La actualidad más candente (20)

Inter process communication
Inter process communicationInter process communication
Inter process communication
 
Aggrement protocols
Aggrement protocolsAggrement protocols
Aggrement protocols
 
Optimistic concurrency control in Distributed Systems
Optimistic concurrency control in Distributed SystemsOptimistic concurrency control in Distributed Systems
Optimistic concurrency control in Distributed Systems
 
Distributed concurrency control
Distributed concurrency controlDistributed concurrency control
Distributed concurrency control
 
Semophores and it's types
Semophores and it's typesSemophores and it's types
Semophores and it's types
 
Inter Process Communication
Inter Process CommunicationInter Process Communication
Inter Process Communication
 
Inter Process Communication
Inter Process CommunicationInter Process Communication
Inter Process Communication
 
SYNCHRONIZATION IN MULTIPROCESSING
SYNCHRONIZATION IN MULTIPROCESSINGSYNCHRONIZATION IN MULTIPROCESSING
SYNCHRONIZATION IN MULTIPROCESSING
 
OS - Process Concepts
OS - Process ConceptsOS - Process Concepts
OS - Process Concepts
 
Interrupt
InterruptInterrupt
Interrupt
 
Operating System - Monitors (Presentation)
Operating System - Monitors (Presentation)Operating System - Monitors (Presentation)
Operating System - Monitors (Presentation)
 
Operating System Process Synchronization
Operating System Process SynchronizationOperating System Process Synchronization
Operating System Process Synchronization
 
Inter Process Communication Presentation[1]
Inter Process Communication Presentation[1]Inter Process Communication Presentation[1]
Inter Process Communication Presentation[1]
 
Interprocess communication (IPC) IN O.S
Interprocess communication (IPC) IN O.SInterprocess communication (IPC) IN O.S
Interprocess communication (IPC) IN O.S
 
Agreement Protocols, distributed File Systems, Distributed Shared Memory
Agreement Protocols, distributed File Systems, Distributed Shared MemoryAgreement Protocols, distributed File Systems, Distributed Shared Memory
Agreement Protocols, distributed File Systems, Distributed Shared Memory
 
Communication in Distributed Systems
Communication in Distributed SystemsCommunication in Distributed Systems
Communication in Distributed Systems
 
Operating system critical section
Operating system   critical sectionOperating system   critical section
Operating system critical section
 
Cpu scheduling in operating System.
Cpu scheduling in operating System.Cpu scheduling in operating System.
Cpu scheduling in operating System.
 
Multi processor scheduling
Multi  processor schedulingMulti  processor scheduling
Multi processor scheduling
 
Processes description and process control.
Processes description and process control.Processes description and process control.
Processes description and process control.
 

Similar a Lecture 5 inter process communication

Module 2 - PPT.pdfModule 2 - PPT.pdfModule 2 - PPT.pdfModule 2 - PPT.pdfModul...
Module 2 - PPT.pdfModule 2 - PPT.pdfModule 2 - PPT.pdfModule 2 - PPT.pdfModul...Module 2 - PPT.pdfModule 2 - PPT.pdfModule 2 - PPT.pdfModule 2 - PPT.pdfModul...
Module 2 - PPT.pdfModule 2 - PPT.pdfModule 2 - PPT.pdfModule 2 - PPT.pdfModul...morganjohn3
 
Intro Basic of OS .ppt
Intro Basic of OS .pptIntro Basic of OS .ppt
Intro Basic of OS .pptVarsha506533
 
Concurrency Control in Distributed Systems.pptx
Concurrency Control in Distributed Systems.pptxConcurrency Control in Distributed Systems.pptx
Concurrency Control in Distributed Systems.pptxMArshad35
 
Multiprocessing -Interprocessing communication and process sunchronization,se...
Multiprocessing -Interprocessing communication and process sunchronization,se...Multiprocessing -Interprocessing communication and process sunchronization,se...
Multiprocessing -Interprocessing communication and process sunchronization,se...Neena R Krishna
 
Lecture 5- Process Synchonization_revised.pdf
Lecture 5- Process Synchonization_revised.pdfLecture 5- Process Synchonization_revised.pdf
Lecture 5- Process Synchonization_revised.pdfAmanuelmergia
 
Operating system 27 semaphores
Operating system 27 semaphoresOperating system 27 semaphores
Operating system 27 semaphoresVaibhav Khanna
 
Unit 2 part 2(Process)
Unit 2 part 2(Process)Unit 2 part 2(Process)
Unit 2 part 2(Process)WajeehaBaig
 
Synchronization
SynchronizationSynchronization
SynchronizationSara shall
 
PROCESS.pptx
PROCESS.pptxPROCESS.pptx
PROCESS.pptxDivyaKS18
 
Lecture 5- Process Synchronization (1).pptx
Lecture 5- Process Synchronization (1).pptxLecture 5- Process Synchronization (1).pptx
Lecture 5- Process Synchronization (1).pptxAmanuelmergia
 
Module-6 process managedf;jsovj;ksdv;sdkvnksdnvldknvlkdfsment.ppt
Module-6 process managedf;jsovj;ksdv;sdkvnksdnvldknvlkdfsment.pptModule-6 process managedf;jsovj;ksdv;sdkvnksdnvldknvlkdfsment.ppt
Module-6 process managedf;jsovj;ksdv;sdkvnksdnvldknvlkdfsment.pptKAnurag2
 
chapter4-processes nd processors in DS.ppt
chapter4-processes nd processors in DS.pptchapter4-processes nd processors in DS.ppt
chapter4-processes nd processors in DS.pptaakarshsiwani1
 
Chapter -2 operating system presentation
Chapter -2 operating system presentationChapter -2 operating system presentation
Chapter -2 operating system presentationchnrketan
 

Similar a Lecture 5 inter process communication (20)

Module 2 - PPT.pdfModule 2 - PPT.pdfModule 2 - PPT.pdfModule 2 - PPT.pdfModul...
Module 2 - PPT.pdfModule 2 - PPT.pdfModule 2 - PPT.pdfModule 2 - PPT.pdfModul...Module 2 - PPT.pdfModule 2 - PPT.pdfModule 2 - PPT.pdfModule 2 - PPT.pdfModul...
Module 2 - PPT.pdfModule 2 - PPT.pdfModule 2 - PPT.pdfModule 2 - PPT.pdfModul...
 
Intro Basic of OS .ppt
Intro Basic of OS .pptIntro Basic of OS .ppt
Intro Basic of OS .ppt
 
Concurrency Control in Distributed Systems.pptx
Concurrency Control in Distributed Systems.pptxConcurrency Control in Distributed Systems.pptx
Concurrency Control in Distributed Systems.pptx
 
Ch03 processes
Ch03 processesCh03 processes
Ch03 processes
 
Multiprocessing -Interprocessing communication and process sunchronization,se...
Multiprocessing -Interprocessing communication and process sunchronization,se...Multiprocessing -Interprocessing communication and process sunchronization,se...
Multiprocessing -Interprocessing communication and process sunchronization,se...
 
IPC
IPCIPC
IPC
 
IPC
IPCIPC
IPC
 
Lecture 5- Process Synchonization_revised.pdf
Lecture 5- Process Synchonization_revised.pdfLecture 5- Process Synchonization_revised.pdf
Lecture 5- Process Synchonization_revised.pdf
 
Operating system 27 semaphores
Operating system 27 semaphoresOperating system 27 semaphores
Operating system 27 semaphores
 
Process coordination
Process coordinationProcess coordination
Process coordination
 
Unit 2 part 2(Process)
Unit 2 part 2(Process)Unit 2 part 2(Process)
Unit 2 part 2(Process)
 
Synchronization
SynchronizationSynchronization
Synchronization
 
CHAP4.pptx
CHAP4.pptxCHAP4.pptx
CHAP4.pptx
 
Ch5 process synchronization
Ch5   process synchronizationCh5   process synchronization
Ch5 process synchronization
 
Os
OsOs
Os
 
PROCESS.pptx
PROCESS.pptxPROCESS.pptx
PROCESS.pptx
 
Lecture 5- Process Synchronization (1).pptx
Lecture 5- Process Synchronization (1).pptxLecture 5- Process Synchronization (1).pptx
Lecture 5- Process Synchronization (1).pptx
 
Module-6 process managedf;jsovj;ksdv;sdkvnksdnvldknvlkdfsment.ppt
Module-6 process managedf;jsovj;ksdv;sdkvnksdnvldknvlkdfsment.pptModule-6 process managedf;jsovj;ksdv;sdkvnksdnvldknvlkdfsment.ppt
Module-6 process managedf;jsovj;ksdv;sdkvnksdnvldknvlkdfsment.ppt
 
chapter4-processes nd processors in DS.ppt
chapter4-processes nd processors in DS.pptchapter4-processes nd processors in DS.ppt
chapter4-processes nd processors in DS.ppt
 
Chapter -2 operating system presentation
Chapter -2 operating system presentationChapter -2 operating system presentation
Chapter -2 operating system presentation
 

Último

Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceanilsa9823
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AIABDERRAOUF MEHENNI
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️anilsa9823
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 

Último (20)

Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 

Lecture 5 inter process communication

  • 2. Introduction - IPC • Since processes frequently need to communicate with other processes therefore, there is a need for a well-structured communication, without using interrupts, among processes. • Processes within a system may be independent or cooperating • Cooperating processes can affect or be affected by other processes, including sharing data. • Cooperating processes need inter-process communication (IPC) • Inter processor communication in a multiprocessor system─ used to generate information about certain sets of computations finishing on one processor and to let the other processors waiting for finishing the computations take note of the information • Similarly, there is inter process communication from a process (task or thread to another)
  • 3. IPC Ctd’ • Reasons for cooperating processes: - Information sharing - Computation speedup - Modularity - Convenience • In IPC, it means that a process (scheduler, task or ISR) generates some information by signal (for other process start) or value (for example of semaphore) or generates an output so that it lets another process take note or use it through the kernel functions for the IPCs
  • 4. Objectives • To cover the following sections: • Critical Section • Mutual Exclusion • Achieving Mutual Exclusion • Semaphores
  • 5. IPC • 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 • Two models of IPC • Shared memory • Message passing
  • 8. Message Passing • Mechanism for process to communicate and synchronize their actions • Message system process communicate with each other without resorting to shared variables • IPC facility provides two operations: • Send(message) –message size fixed or variable • Receive(message) • If P and Q wish to communicate, they need to: Establish a communication link between them Exchange messages via send/receive • Implementation of communication link Physical (e.g shared memory ], hardware bus) Logical( e.g direct or indirect, synchronous or asynchronous)
  • 9. Message Passing • Implementation questions • How are links established? • Can a link be associated with more than two processes? • How many links can there be between every pair of communicating processes? • What is the capacity of a link? • Is the size of a message that the link can accommodate fixed or variable? • Is a link unidirectional or bi-directional?
  • 10. 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 • Properties of direct communication link • A link is associated with exactly one pair of communicating processes • Between each pair there exists exactly one link • The link may be unidirectional, but is usually bi-directional
  • 11. Indirect Communication • Messages are directed and received mailboxes(also referred to as ports) • Each mailbox has a unique id • Processes can communicate only if they share a mailbox • Properties of communication link Link established only if processes share a common mailbox A link may be associated with many processes Each pair of processes may share several communication links Link may be unidirectional or bi-directional
  • 13. Mechanisms • Transfer data/info between address spaces • Maintain protection and isolation • Provide flexibility and performance • Processess Write(send) and read(receive) Advantage is that OS manages Disadvantage is overheads
  • 15. Shared memory IPC • OS establishes shared channel and maps it into each process address space • Processes directly read/write from this memory • OS is out of the way
  • 16. Race Conditions • In operating systems, processes that are working together share some common storage (main memory, file etc.) that each process can read and write. • When two or more processes are reading or writing some shared data and the final result depends on who runs precisely when, are called race conditions. • Concurrently executing threads that share data need to synchronize their operations and processing in order to avoid race condition on shared data. • Only one ‘customer’ thread at a time should be allowed to examine and update the shared variable. • Race conditions are also possible in Operating Systems. • If the ready queue is implemented as a linked list and if the ready queue is being manipulated during the handling of an interrupt, then interrupts must be disabled to prevent another interrupt before the first one completes. • If interrupts are not disabled then the linked list could become corrupt.
  • 17. Critical Section • The key to preventing trouble involving shared storage is find some way to prohibit more than one process from reading and writing the shared data simultaneously. • That part of the program where the shared memory is accessed is called the Critical Section. • To avoid race conditions and flawed results, one must identify codes in Critical Sections in each thread.
  • 18. • The characteristic properties of the code that form a Critical Section are Codes that reference one or more variables in a “read-update-write” fashion while any of those variables is possibly being altered by another thread. Codes that alter one or more variables that are possibly being referenced in “read-update-write” fashion by another thread. Codes use a data structure while any part of it is possibly being altered by another thread. Codes alter any part of a data structure while it is possibly in use by another thread. • Here, the important point is that when one process is executing shared modifiable data in its critical section, no other process is to be allowed to execute in its critical section. • Thus, the execution of critical sections by the processes is mutually exclusive in time.
  • 19. Mutual Exclusion • A way of making sure that if one process is using a shared modifiable data, the other processes will be excluded from doing the same thing. • Formally, while one process executes the shared variable, all other processes desiring to do so at the same time moment should be kept waiting; when that process has finished executing the shared variable, one of the processes waiting; while that process has finished executing the shared variable, one of the processes waiting to do so should be allowed to proceed. • In this fashion, each process executing the shared data (variables) excludes all others from doing so simultaneously. This is called Mutual Exclusion. • Note that mutual exclusion needs to be enforced only when processes access shared modifiable data - when processes are performing operations that do not conflict with one another they should be allowed to proceed concurrently.
  • 20. Mutual Exclusion Conditions • If we could arrange matters such that no two processes were ever in their critical sections simultaneously, we could avoid race conditions. • We need four conditions to hold to have a good solution for the critical section problem (mutual exclusion). i. No two processes may at the same moment inside their critical sections. ii. No assumptions are made about relative speeds of processes or number of CPUs. iii. No process, outside its critical section, should block other processes. iv. No process should wait arbitrary long to enter its critical section.
  • 21. Proposals for Achieving Mutual Exclusion • The mutual exclusion problem is to devise a pre-protocol (or entry protocol) and a post-protocol (or exist protocol) to keep two or more threads from being in their critical sections at the same time. • Tanenbaum examine proposals for critical-section problem or mutual exclusion problem. Problem • When one process is updating shared modifiable data in its critical section, no other process should allowed to enter in its critical section.
  • 22. Proposal 1 -Disabling Interrupts (Hardware Solution) • Each process disables all interrupts just after entering in its critical section and re-enable all interrupts just before leaving critical section. • With interrupts turned off the CPU could not be switched to other process. • Hence, no other process will enter its critical and mutual exclusion achieved. Conclusion • Disabling interrupts is sometimes a useful technique within the kernel of an operating system, but it is not appropriate as a general mutual exclusion mechanism for users process. • The reason is that it is unwise to give user process the power to turn off interrupts.
  • 23. Proposal 2 - Lock Variable (Software Solution) • In this solution, we consider a single, shared, (lock) variable, initially 0. • When a process wants to enter in its critical section, it first test the lock. • If lock is 0, the process first sets it to 1 and then enters the critical section. • If the lock is already 1, the process just waits until (lock) variable becomes 0. • Thus, a 0 means that no process in its critical section, and 1 means hold your horses - some process is in its critical section. Conclusion • The flaw in this proposal can be best explained by example. • Suppose process A sees that the lock is 0. • Before it can set the lock to 1 another process B is scheduled, runs, and sets the lock to 1. • When the process A runs again, it will also set the lock to 1, and two processes will be in their critical section simultaneously.
  • 24. Proposal 3 - Strict Alteration • In this proposed solution, the integer variable 'turn' keeps track of whose turn is to enter the critical section. • Initially, process A inspect turn, finds it to be 0, and enters in its critical section. • Process B also finds it to be 0 and sits in a loop continually testing 'turn' to see when it becomes 1. • Continuously testing a variable waiting for some value to appear is called the Busy-Waiting. Conclusion • Taking turns is not a good idea when one of the processes is much slower than the other. • Suppose process 0 finishes its critical section quickly, so both processes are now in their non-critical section. • This situation violates above mentioned condition 3.
  • 25. Using Systems calls 'sleep' and 'wakeup' • Basically, what above mentioned solution do is this: when a processes wants to enter in its critical section , it checks to see if the entry is allowed. • If it is not, the process goes into tight loop and waits (i.e., start busy waiting) until it is allowed to enter. This approach waste CPU-time. • Now looking at some inter-process communication primitives: is the pair of sleep-wakeup. Sleep • It is a system call that causes the caller to block, that is, be suspended until some other process wakes it up. Wakeup • It is a system call that wakes up the process. • Both 'sleep' and 'wakeup' system calls have one parameter that represents a memory address used to match up 'sleeps' and 'wakeups' .
  • 26. Producer-Consumer Problem • Producer-consumer problem is a common paradigm for cooperating processes • Producer process produces information that is consumed by a consumer process - One solution is to use shared memory for the two processes to communicate - Useful to have a buffer that can be filled by the producer and emptied by the consumer if they are to run concurrently • Unbounded-buffer places no practical limit on the size of the buffer • Bounded-buffer assumes that there is a fixed buffer size • The bounded buffer producers and consumers assumes that there is a fixed buffer size i.e., a finite numbers of slots are available.
  • 27. The Bounded Buffer Producers and Consumers Statement To suspend the producers when the buffer is full, to suspend the consumers when the buffer is empty, and to make sure that only one process at a time manipulates a buffer so there are no race conditions or lost updates. • As an example how sleep-wakeup system calls are used, consider the producer-consumer problem also known as bounded buffer problem. • Two processes share a common, fixed-size (bounded) buffer. The producer puts information into the buffer and the consumer takes information out. • Trouble arises when i. The producer wants to put a new data in the buffer, but buffer is already full. Solution: Producer goes to sleep and to be awakened when the consumer has removed data. ii. The consumer wants to remove data the buffer but buffer is already empty. Solution: Consumer goes to sleep until the producer puts some data in buffer and wakes consumer up. Conclusion • This approaches also leads to same race conditions we have seen in earlier approaches. • Race condition can occur due to the fact that access to 'count' is unconstrained. • The essence of the problem is that a wakeup call, sent to a process that is not sleeping, is lost.
  • 28. Semaphores • E.W. Dijkstra (1965) abstracted the key notion of mutual exclusion in his concepts of semaphores. • Definition A semaphore is a protected variable whose value can be accessed and altered only by the operations P and V and initialization operation called 'Semaphoiinitislize'. • Binary Semaphores can assume only the value 0 or the value 1 counting semaphores also called general semaphores can assume only nonnegative values. • The P (or wait or sleep or down) operation on semaphores S, written as P(S) or wait (S), operates as follows: • P(S): IF S > 0 THENS := S - 1 ELSE (wait on S)
  • 29. • The V (or signal or wakeup or up) operation on semaphore S, written as V(S) or signal (S), operates as follows: • V(S): IF (one or more process are waiting on S) THEN (let one of these processes proceed) ELSE S := S +1 • Operations P and V are done as single, indivisible, atomic action. • It is guaranteed that once a semaphore operations has stared, no other process can access the semaphore until operation has completed. • Mutual exclusion on the semaphore, S, is enforced within P(S) and V(S). • If several processes attempt a P(S) simultaneously, only process will be allowed to proceed. T • he other processes will be kept waiting, but the implementation of P and V guarantees that processes will not suffer indefinite postponement. • Semaphores solve the lost-wakeup problem.
  • 30. Producer-Consumer Problem Using Semaphores • The Solution to producer-consumer problem uses three semaphores, namely, full, empty and mutex. • The semaphore 'full' is used for counting the number of slots in the buffer that are full. • The 'empty' for counting the number of slots that are empty and semaphore 'mutex' to make sure that the producer and consumer do not access modifiable shared section of the buffer simultaneously. • Initialization  Set full buffer slots to 0. (i.e., semaphore Full = 0.)  Set empty buffer slots to N. (i.e., semaphore empty = N.)  For control access to critical section set mutex to 1. (i.e., semaphore mutex = 1.)
  • 31. Producer-Consumer Problem Using Semaphores • Producer ( ) WHILE (true) produce-Item ( ); P (empty); P (mutex); enter-Item ( ) V (mutex) V (full); • Consumer ( ) WHILE (true) P (full) P (mutex); remove-Item ( ); V (mutex); V (empty); consume-Item (Item)