0% found this document useful (0 votes)
9 views94 pages

Co3 Eos

The document covers the topic of Process Synchronization in operating systems, detailing various synchronization problems and techniques such as semaphores and critical sections. It outlines the objectives, learning outcomes, and classic synchronization problems like the Dining Philosophers and Bounded Buffer problems. Additionally, it discusses the advantages and disadvantages of semaphores, as well as solutions to synchronization issues to ensure data consistency and prevent deadlocks.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views94 pages

Co3 Eos

The document covers the topic of Process Synchronization in operating systems, detailing various synchronization problems and techniques such as semaphores and critical sections. It outlines the objectives, learning outcomes, and classic synchronization problems like the Dining Philosophers and Bounded Buffer problems. Additionally, it discusses the advantages and disadvantages of semaphores, as well as solutions to synchronization issues to ensure data consistency and prevent deadlocks.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 94

BCA

Topic : Process Synchronization


ESSENTIALS OF OPERATING SYSTEM
Module - 3 Unit – 1&2

A.Siddhartha
Asst. Professor

CREATED BY K. VICTOR BABU


AIM

To familiarize students with the scheduling and different types of cpu scheduling algorithms

INSTRUCTIONAL OBJECTIVES

In this unit, the students will be able to:


Learn about the Process synchronization problems

LEARNING OUTCOMES

At the end of this unit, you should be able to:


 Improvement of knowledge about Process Synchronization
 Deliberate various Process synchronization problems

CREATED BY K. VICTOR BABU


Co3:Syllabus
• Process Synchronization: Critical Section Problem, Mutual Exclusion,
Races, Semaphores, Classic Synchronization Problems,
Readers/Writers, Dining Philosophers. Deadlocks: Deadlocks and
Starvation, System Model, Necessary Conditions for a deadlock,
Mutual Exclusion, Hold and Wait, No Pre-emption, Circular wait,
Resource Allocation Graphs, Handling Deadlocks, Prevention,
Avoidance, Bankers Algorithm.. I/O Device Management, I/O Device
Types and Characteristics

CREATED BY K. VICTOR BABU


Process Synchronization:
• Critical Section Problem,
• Classic problems of synchronization-
 Readers/Writers,
 Dining Philosophers,
• Monitors.

CREATED BY K. VICTOR BABU


CREATED BY K. VICTOR BABU
Process Synchronization
• Process Synchronization is used in a computer system to ensure that
multiple processes or threads can run concurrently without
interfering with each other.
• The main objective of process synchronization is to ensure that
multiple processes access shared resources without interfering with
each other and to prevent the possibility of inconsistent data due to
concurrent access.
• To achieve this, various synchronization techniques such as
semaphores, monitors, and critical sections are used.

CREATED BY K. VICTOR BABU


• In a multi-process system, synchronization is necessary to ensure data
consistency and integrity, and to avoid the risk of deadlocks and other
synchronization problems.

CREATED BY K. VICTOR BABU


CREATED BY K. VICTOR BABU
CREATED BY K. VICTOR BABU
CREATED BY K. VICTOR BABU
Critical Section in
Synchronization
• A critical section is a part of a program where shared resources like memory or
files are accessed by multiple processes or threads.
• To avoid issues like data inconsistency or race conditions, synchronization
techniques ensure that only one process or thread uses the critical section at a
time.

The wait() method controls the entry to the critical section, whereas the signal() function
controls the exit.
CREATED BY K. VICTOR BABU
The following are the four most important parts of the critical section:
• Entry Section: It is a step in the process that determines whether or
not a process may begin.
• Critical Section: This section enables a single process to access and
modify a shared variable.
• Exit Section: Other processes waiting in the Entry Section are able to
enter the Critical Sections through the Exit Section. It also ensures that
a process that has completed its execution gets deleted via this
section.
• Remainder Section: The Remainder Section refers to the rest of the
code that isn't in the Critical, Entry, or Exit sections.

CREATED BY K. VICTOR BABU


Solutions to the Critical Section Problem
To effectively address the Critical Section Problem in operating systems,
any solution must meet three key requirements:
• Mutual Exclusion: Mutual exclusion implies that only one process can be
inside the critical section at any time. If any other processes require the
critical section, they must wait until it is free.
• Progress: Progress means that if a process is not using the critical section,
then it should not stop any other process from accessing it. In other
words, any process can enter a critical section if it is free.
• Bounded Waiting: There exists a bound, or limit, on the number of times
that other processes are allowed to enter their critical sections after a
process has made a request to enter its critical section and before that
request is granted.
CREATED BY K. VICTOR BABU
Two general approaches are used to handle critical sections:
• Preemptive kernels: A preemptive kernel allows a process to be
preempted while it is running in kernel mode.
• Non preemptive kernels: A non-preemptive kernel does not allow a
process running in kernel mode to be preempted. A kernel-mode
process will run until it exists in kernel mode, blocks, or voluntarily
yields control of the CPU.
• A non-preemptive kernel is essentially free from race conditions on
kernel data structures, as only one process is active in the kernel at a
time.

CREATED BY K. VICTOR BABU


Two types of solutions
• Software solution(Peter son’s Solution)
• Hardware solution(Synchronization Hardware)

CREATED BY K. VICTOR BABU


CREATED BY K. VICTOR BABU
CREATED BY K. VICTOR BABU
Semaphores in OS
• It is an integer variable which can be used as a shared variable to
prevent the race condition, that is shared by multiple processes.
• Means if there are P1,P2,P3,P4,P5 then all the 5 processes can make
use of Semaphores.
• We can initialize the value of Semaphore and is accessed by 2
standard (atomic ) operations.
• Wait() and signal() that are used for process synchronization.

CREATED BY K. VICTOR BABU


Wait:
The Wait Operation is used for deciding the condition for the process to enter the
critical state or wait for execution of process. Here, the wait operation has many
different names. The different names are:
• Sleep Operation
• Down Operation
• Decrease Operation
• P Function (most important alias name for wait operation)
The Wait Operation works on the basis of Semaphore or Mutex Value.
Here, if the Semaphore value is greater than zero or positive then the Process can
enter the Critical Section Area.
If the Semaphore value is equal to zero then the Process has to wait for the
Process to exit the Critical Section Area.
CREATED BY K. VICTOR BABU
• This function is only present until the process enters the critical state. If
the Processes enters the critical state, then the P Function or Wait
Operation has no job to do.
• If the Process exits the Critical Section we have to reduce the value of
Semaphore

wait(S)
{
while (S<=0);
S--;
}
CREATED BY K. VICTOR BABU
Signal()
The Signal Semaphore Operation is used to update the value of Semaphore.
The Semaphore value is updated when the new processes are ready to enter
the Critical Section.
The Signal Operation is also known as:
• Wake up Operation
• Up Operation
• Increase Operation
• V Function (most important alias name for signal operation)
We know that the semaphore value is decreased by one in the wait operation
when the process left the critical state. So, to counter balance the decreased
number 1 we use signal operation which increments the semaphore value.
This induces the critical section to receive more and more processes into it.

CREATED BY K. VICTOR BABU


Signal

• The most important part is that this Signal Operation or V Function is


executed only when the process comes out of the critical section. The
value of semaphore cannot be incremented before the exit of process
from the critical section
• The signal operation increments the value of its argument S.

signal(S)
{
S++;
}
CREATED BY K. VICTOR BABU
Types of Semaphores

There are two main types of semaphores i.e. counting


semaphores and binary semaphores
• Counting Semaphores
• Binary Semaphores

CREATED BY K. VICTOR BABU


Binary Semaphores
• Here, there are only two values of Semaphore in Binary Semaphore
Concept. The two values are 1 and 0.
• If the Value of Binary Semaphore is 1, then the process has the
capability to enter the critical section area.
• If the value of Binary Semaphore is 0 then the process does not have
the capability to enter the critical section area.

CREATED BY K. VICTOR BABU


Counting Semaphores
• Here, there are two sets of values of Semaphore in Counting
Semaphore Concept. The two types of values are values
greater than and equal to one and other type is value equal
to zero.
• If the Value of Binary Semaphore is greater than or equal to
1, then the process has the capability to enter the critical
section area.
• If the value of Binary Semaphore is 0 then the process does
not have the capability to enter the critical section area.
CREATED BY K. VICTOR BABU
• Advantages of Semaphores
Some of the advantages of semaphores are as follows −
• Semaphores allow only one process into the critical section.
They follow the mutual exclusion.
• There is no resource wastage because of busy waiting in
semaphores as processor time is not wasted unnecessarily.
• To prevent Race condition.
• To prevent deadlocks

CREATED BY K. VICTOR BABU


Disadvantages of Semaphores
Some of the disadvantages of semaphores are as follows −
• Semaphores are complicated so the wait and signal operations
must be implemented in the correct order to prevent deadlocks.
• Semaphores may lead to a priority inversion where low priority
processes may access the critical section first and high priority
processes later.
• More number of semaphores may lead to high maintenance.
• Difficult to debug if any synchronization problem occurs.

CREATED BY K. VICTOR BABU


Classic Synchronization Problems

• Bounded Buffer problem using semaphore(producer


consumer)
• Dining Philosophers Problem
• The Readers Writers Problem

CREATED BY K. VICTOR BABU


Bounded Buffer Problem Using
Semaphores
What is the Bounded Buffer Problem?
• A Producer produces items and puts them into a fixed-size buffer.
• A Consumer takes items from the buffer and uses them.
• The buffer has a limited size, meaning
a) The producer should not add items if the buffer is full, and
b) The consumer should not take items if the buffer is empty.
Issues in Synchronization
• Race Condition: If multiple processes access the buffer simultaneously, it can cause
data inconsistency.
• Deadlock: If not managed properly, the system may freeze.
• Starvation: If one process never gets a chance to execute, it may be blocked
indefinitely
CREATED BY K. VICTOR BABU
Solution Using Semaphores
We use three semaphores:
1.mutex (Binary Semaphore - 1 or 0): which is used to acquire and release the
locks
2.empty (Counting Semaphore): A counting semaphore whose initial value is the
number of slots in the buffer, since initially all slots are empty
3.full (Counting Semaphore): is a counting semaphore it keeps track of filled slots
in the buffer whose initial value is 0

1)Initialization:
• Semaphore mutex = 1; // Controls buffer access
• Semaphore empty = N; // Number of empty slots (buffer size)
• Semaphore full = 0; // Number of filled slots

CREATED BY K. VICTOR BABU


Producer Process:
do{
produce_item(); // Create an item
wait(empty); // Check if there is space in the buffer wait until
empty>0 and then decrement empty
wait(mutex); // Enter critical section(acquire lock) add_to_buffer();
// Place item in buffer
signal(mutex); // Exit critical section(release lock)
signal(full); // Increase count of filled slots(full)
}while (true)

CREATED BY K. VICTOR BABU


Consumer Process:
do{
consume_item(); // Create an item
wait(full); // Check if there is space in the buffer wait until
full>0 and then decrement full
wait(mutex); // Enter critical section(acquire lock)
remove_from_buffer(); // Remove item in buffer
signal(mutex); // Exit critical section(release lock)
signal(empty); // Increase count of empty slots(empty)
}while (true)
CREATED BY K. VICTOR BABU
How It Works?
•Producer waits if the buffer is full (empty == 0).
•Consumer waits if the buffer is empty (full == 0).
•Mutex ensures only one process (producer or consumer) accesses the
buffer at a time.
• Advantages of Using Semaphores:
• ✅ Prevents race conditions
✅ Avoids data inconsistency
✅ Synchronizes producer and consumer efficiently

CREATED BY K. VICTOR BABU


Dining Philosophers Problem

• What is the Problem Statement?


• Consider there are five philosophers sitting around a circular
dining table. The dining table has five chopsticks and a bowl of
rice in the middle as shown in the below figure. At any instant, a
philosopher is either eating or thinking. When a philosopher
wants to eat, he uses two chopsticks - one from their left and
one from their right. When a philosopher wants to think, he
keeps down both chopsticks at their original place.

CREATED BY K. VICTOR BABU


CREATED BY K. VICTOR BABU
Problem Statement:
• Imagine five philosophers sitting around a circular table.
• Each philosopher has a plate of food but needs two forks to eat.
• There are exactly five forks, one between each pair of philosophers.
• Philosophers either think or eat—they cannot do both at the same
time.
• To eat, a philosopher must pick up the fork on their left and right.
• If a philosopher cannot pick up both forks, they must put down any
fork they have picked up and continue thinking.

CREATED BY K. VICTOR BABU


Here's the Solution

• From the problem statement, it is clear that a


philosopher can think for an indefinite amount of time.
• But when a philosopher starts eating, he has to stop at
some point of time.
• The philosopher is in an endless cycle of thinking and
eating.

CREATED BY K. VICTOR BABU


• while(TRUE)
•{
• wait(stick[i]);
• /* mod is used because if i=5, next
• chopstick is 1 (dining table is circular) */
• wait(stick[(i+1) % 5]);
• /* eat */
• signal(stick[i]);
• signal(stick[(i+1) % 5]);
• /* think */
•}
CREATED BY K. VICTOR BABU
Solutions

CREATED BY K. VICTOR BABU


• When a philosopher wants to eat the rice, he will wait
for the chopstick at his left and picks up that chopstick.
• Then he waits for the right chopstick to be available,
and then picks it too. After eating, he puts both the
chopsticks down.
• But if all five philosophers are hungry simultaneously,
and each of them pickup one chopstick, then a deadlock
situation occurs because they will be waiting for another
chopstick forever. The possible solutions for this are:

CREATED BY K. VICTOR BABU


• A philosopher must be allowed to pick up the chopsticks
only if both the left and right chopsticks are available.
• Allow only four philosophers to sit at the table.
• That way, if all the four philosophers pick up four
chopsticks, there will be one chopstick left on the table
• . So, one philosopher can start eating and eventually,
two chopsticks will be available. In this way, deadlocks
can be avoided.

CREATED BY K. VICTOR BABU


What is Readers Writer Problem?

• The Problem Statement


• There is a shared resource that should be accessed by
multiple processes. There are two types of processes in this
context. They are reader and writer.
• Any number of readers can read from the shared resource
simultaneously, but only one writer can write to the shared
resource.
• When a writer is writing data to the resource, no other
process can access the resource.
• A writer cannot write to the resource if there are non-zero
number of readers accessing the resource at that time.
CREATED BY K. VICTOR BABU
The Solution

• From the above problem statement, it is evident that


readers have higher priority than writer. If a writer
wants to write to the resource, it must wait until there
are no readers currently accessing that resource.
• Here, we use one mutex m and a semaphore w. An
integer variable read_count is used to maintain the
number of readers currently accessing the resource. The
variable read_count is initialized to 0. A value of 1 is
given initially to m and w.

CREATED BY K. VICTOR BABU


• Instead of having the process to acquire lock on the shared resource,
we use the mutex m to make the process to acquire and release lock
whenever it is updating the read_count variable.

CREATED BY K. VICTOR BABU


The code for the writer process looks like this

• while(TRUE)
•{
• wait(w);

• /* perform the write operation */

• signal(w);
•}

CREATED BY K. VICTOR BABU


And, the code for the reader process looks like this:
• while(TRUE)
• {
• //acquire lock
• wait(m);
• read_count++;


if(read_count == 1) }Entry sec
• wait(w);
• //release lock
• signal(m);
CREATED BY K. VICTOR BABU
• /* perform the reading operation */

• // acquire lock
• wait(m);
• read_count--;
• if(read_count == 0)


signal(w); }Exit sec

• // release lock
• signal(m);
•}
CREATED BY K. VICTOR BABU
Here is the Code uncoded(explained)

• As seen above in the code for the writer, the writer just
waits on the w semaphore until it gets a chance to write
to the resource.
• After performing the write operation, it increments w so
that the next writer can access the resource.
• On the other hand, in the code for the reader, the lock is
acquired whenever the read_count is updated by a
process.
• When a reader wants to access the resource, first it
increments the read_count value, then accesses the
resource and then decrements the read_count value.
CREATED BY K. VICTOR BABU
• The semaphore w is used by the first reader which enters the
critical section and the last reader which exits the critical
section.
• The reason for this is, when the first reader enters the critical
section, the writer is blocked from the resource. Only new
readers can access the resource now.
• Similarly, when the last reader exits the critical section, it
signals the writer using the w semaphore because there are
zero readers now and a writer can have the chance to access
the resource.

CREATED BY K. VICTOR BABU


SYSTEM MODEL
• In system there are finite number of resources.
• We will distribute these resources to different processes.
• We will partition those resources in to several types.
• Examples: Memory space, I/O devices
• Process request the resource before using it.
• It must release the resource after using it.
• A process can request any number of resources.
• But the thing is number of requested resources should not be greater
than available resources
CREATED BY K. VICTOR BABU
Normal Mode:
• Each process utilizes the resourse as follows:
• Request: Process request resource
• If it is not grant(using by some other process)it goes to wait for state.
• Uses: IF it is available it uses that resources(it will operate on that resource)
• Release: It will release the resource after using it.
• Examples:
• Request() & Release() ---- for device
• Open() & Close() ----- for File
• Allocate() & Free() ----- for Memory.

CREATED BY K. VICTOR BABU


• Deadlocks can occur when we are using same resource types or
different resource types.
• Same resource types:
• If the system having 3 cd drives.
• Consider that 3 processes holds one of these 3 drives.
• If each process request another device then the 3 processes will be in
deadlock state.

CREATED BY K. VICTOR BABU


• Different resource types:
• If the system having printer, DVD drive.
• If Pi holds printer, Pj holds DVD.
• If Pi requests for DVD and Pj requests for printer then Deadlock will
occur in this situation also.

CREATED BY K. VICTOR BABU


DEADLOCKS

• In multiprogramming several processes may


compete for resources
• If a process requests a resource and the resource is
not available then the process will go to the
waiting state.
• Sometimes the state of the process could not
change because the resources which are requested
by that process are held by another process, and
this situation is called a DEADLOCK state.
CREATED BY K. VICTOR BABU
CREATED BY K. VICTOR BABU
Necessary Conditions for Deadlock

The four necessary conditions for a deadlock to arise are as follows.

• Mutual Exclusion: Only one process can use a resource at any given
time i.e. the resources are non-sharable.

• Hold and wait: A process is holding at least one resource at a time


and is waiting to acquire other resources held by some other process.

CREATED BY K. VICTOR BABU


• No preemption: The resource can be released by a process voluntarily
i.e. after execution of the process.

• Circular Wait: A set of processes are waiting for each other in a


circular fashion. For example, lets say there are a set of processes {P0​
,P1​,P2​,P3​} such that P0​depends on P1​, P1​depends on P2​, P2​
depends on P3​and P3​depends on P0​. This creates a circular
relation between all these processes and they have to wait forever to
be executed.

CREATED BY K. VICTOR BABU


Starvation
Starvation is a resource management problem in os, when some processes keep
waiting indefinitely because higher-priority processes keep getting the resources
first.
• Example:
• A low-priority process is waiting for CPU time.
• But higher-priority processes keep coming and using the CPU.
• The low-priority process may never get a chance to execute, leading to starvation.
Difference b/w Deadlock& Starvation:
• Deadlock: No process can proceed because they are stuck waiting for each other.
• Starvation: Some processes keep waiting forever because they are ignored by the
system.

CREATED BY K. VICTOR BABU


Resource Allocation Graph
• A Resource Allocation Graph (RAG) is a graphical representation used in Operating
Systems to visualize how resources are allocated to processes and whether there’s a
risk of deadlock.
• It has all the information about the resource allocation to each process and the
request of each process.
• In Banker's Algorithm, we have table-like data that suggests all the information
about the allocation of resources to the processes and their requests.
• We determine the state of a system using those data from the table. But, RAG
summarizes all the information in its pictorial or graphical form.
• In some cases, we can determine there is a deadlock in the system or not, just after
looking at the Resource Allocation Graph or (RAG), but it is not possible by just
looking at the table. This is one of the advantages of the Resource Allocation Graph.

CREATED BY K. VICTOR BABU


Representation of Resource Allocation Graph (RAG)
• Like all other graphs, it also has vertices and edges.
• The vertices of the RAG represent the process or the resource, and the
edges represent the allocation or request of any resource.
• As both the process and resource are the vertices of the graph, generally,
the process vertex will be represented using the circle and the resource
vertex using the rectangle.
• The resource can be of two types:
• Single Instance - It contains the single instance of the resource, and is
represented by a single dot inside the rectangle which is the resource
vertex.
• Multiple Instance - It contains the multiple instances of the resource, and
is represented by multiple (more than one) dots inside the rectangle.
CREATED BY K. VICTOR BABU
CREATED BY K. VICTOR BABU
Edges:
• Request Edge: This edge directing from the resource towards the
process represents the allocation of the resource to the process.
• From a process to a resource (P → R) – the process is requesting that
resource.
Assignment Edge: This edge directing from the process towards the
resource represents the request of the resource by the process
• From a resource to a process (R → P) – the resource is currently
assigned to that process.

CREATED BY K. VICTOR BABU


Basic Elements of a Resource Allocation Graph:
• Processes: Represented as circles (e.g., P1, P2, P3)
• Resources: Represented as squares (e.g., R1, R2)

Example:
Let’s say:
• P1 is requesting R1
• R1 is assigned to P2
• P2 is requesting R2
• R2 is assigned to P1

CREATED BY K. VICTOR BABU


• Resource Allocation graph with deadlock
• Whenever there is no cycle in RAG deadlock will not occur
• Suppose if there is a cycle in RAG deadlock may or may not occur,
there may be a chance.

CREATED BY K. VICTOR BABU


• Resource Allocation graph with cycle but no deadlock
• If graph contains no cycle there is no deadlock
• Suppose if graph contains a cycle having only once instance per resource then
deadlock occures.
• Whenever you have a multiple instances are present in the resources there may
be a chance with no deadlocks

CREATED BY K. VICTOR BABU


Deadlock Handling-

CREATED BY K. VICTOR BABU


Deadlock Prevention-

• This strategy involves designing a system that violates one of


the four necessary conditions required for the occurrence of
deadlock.
• This ensures that the system remains free from the deadlock.
• The various conditions of deadlock occurrence may be violated
as-

CREATED BY K. VICTOR BABU


1. Mutual Exclusion-

• To violate this condition, all the system resources must be such


that they can be used in a shareable mode.
• In a system, there are always some resources which are
mutually exclusive by nature.
• So, this condition can not be violated.

CREATED BY K. VICTOR BABU


• What is Mutual Exclusion?
• Mutual exclusion means only one process (or person) can use a resource
at a time.
Example
If there is only one chair, only one person can sit on it. Others have to wait
until it’s free.
How It Relates to Deadlock:
• Mutual exclusion is one of the reasons deadlock can happen.
• If multiple processes need the same resource, and only one can use it at a
time, it can lead to waiting — and if not handled carefully, deadlock.

CREATED BY K. VICTOR BABU


Some resources must be used one at a time. You can’t print two documents
at once on the same printer, for example.
• So we usually can’t remove mutual exclusion.
• Instead, we **focus on preventing the other three conditions** (like hold-
and-wait or circular wait).
Example:
• Imagine you have **one printer**.
• ‍Process A wants to print.
• ‍Process B also wants to print.
• Because the printer can only handle **one job at a time**, that’s **mutual
exclusion**.

CREATED BY K. VICTOR BABU


2. Hold and Wait

• This condition can be violated in the following ways-

• Approach-01:

• In this approach,
• A process has to first request for all the resources it requires for execution.
• Once it has acquired all the resources, only then it can start its execution.
• This approach ensures that the process does not hold some resources and
wait for other resources.

CREATED BY K. VICTOR BABU


Drawbacks-

• The drawbacks of this approach are-


• It is less efficient.
• It is not implementable since it is not possible to predict in
advance which resources will be required during execution.

CREATED BY K. VICTOR BABU


• Approach-02:

In this approach,
• A process is allowed to acquire the resources it desires at the current
moment.
• After acquiring the resources, it start its execution.
• Now before making any new request, it has to compulsorily release all the
resources that it holds currently.
• A process can request a resource only when that process is holding no
resources.(No hold is here only wait is there)
• This approach is efficient and implementable.

CREATED BY K. VICTOR BABU


• Approach-03:
In this approach,

• A timer is set after the process acquires any resource.


• After the timer expires, a process has to compulsorily release the
resource.

CREATED BY K. VICTOR BABU


3. No Preemption-

• To prevent deadlock by violating the No Preemption condition, we allow resources


to be preempted under certain conditions.
• 🔧 Strategy:
• If a process requests a resource and it's not available (because another process holds
it), the requesting process must release all the resources it currently holds and retry
later.
• 📌 Example:
• Suppose Process A holds Resource 1 and wants Resource 2 (currently held by
Process B).
• Instead of waiting (which could cause a deadlock), Process A is forced to release
Resource 1.
• Later, it can try again to acquire both resources together.
CREATED BY K. VICTOR BABU
• This condition can by violated by forceful preemption.
• Consider a process is holding some resources and request other
resources that can not be immediately allocated to it.
• Then, by forcefully preempting the currently held resources, the
condition can be violated.

CREATED BY K. VICTOR BABU


4. Circular Wait-
• This condition can be violated by not allowing the processes to wait for resources in a
cyclic manner.
• To violate this condition, the following approach is followed-
• Approach-
• A natural number is assigned to every resource.
• Each process is allowed to request for the resources either in only increasing or only
decreasing order of the resource number.
• In case increasing order is followed, if a process requires a lesser number resource,
then it must release all the resources having larger number and vice versa.
• This approach is the most practical approach and implementable.
• However, this approach may cause starvation but will never lead to deadlock.

CREATED BY K. VICTOR BABU
Deadlock Avoidance-

• This strategy involves maintaining a set of data using which a


decision is made whether to entertain the new request or not.
• If entertaining the new request causes the system to move in an
unsafe state, then it is discarded.
• This strategy requires that every process declares its maximum
requirement of each resource type in the beginning.
• The main challenge with this approach is predicting the
requirement of the processes before execution.
• Banker’s Algorithm is an example of a deadlock avoidance
strategy.
CREATED BY K. VICTOR BABU
• If there is single instance –resource allocation graph
• Multiple instance-Bankers algorithm(safety algorithm, resource-
request algorithm)

CREATED BY K. VICTOR BABU


• Banker’s Algorithm Example Solutions Exercise 1 Assume that there are 5 processes, P0 through
P4, and 4 types of resources. At T0 we have the following system state: Max Instances of
ReBanker’s Algorithm Example Solutions
• Exercise 1
• Assume that there are 5 processes, P0 through P4, and 4 types of resources. At T0 we have the
• following system state:
• Max Instances of Resource Type A = 3 (2 allocated + 1 Available)
• Max Instances of Resource Type B = 17 (12 allocated + 5 Available)
• Max Instances of Resource Type C = 16 (14 allocated + 2 Available)

CREATED BY K. VICTOR BABU


CREATED BY K. VICTOR BABU
CREATED BY K. VICTOR BABU
CREATED BY K. VICTOR BABU
CREATED BY K. VICTOR BABU
CREATED BY K. VICTOR BABU
CREATED BY K. VICTOR BABU
Deadlock Detection and
Recovery-

• This strategy involves waiting until a deadlock occurs.
• After deadlock occurs, the system state is recovered.
• The main challenge with this approach is detecting the
deadlock.

CREATED BY K. VICTOR BABU


CREATED BY K. VICTOR BABU
I/O Device Management,I/O Device Types andCharacteristics.

• I/O (Input/Output) device management is a crucial function of the operating


system (OS) that handles communication between the system and peripheral
devices like keyboards, mice, printers, disk drives, etc.
✨ Objectives of I/O Device Management:
• Efficient Communication: Enable smooth interaction between devices and
CPU/memory.
• Buffering and Caching: Manage temporary storage of data to improve
performance.
• Device Scheduling: Decide the order in which devices are accessed.
• Error Handling: Detect and handle errors during data transmission.
• Providing a Uniform Interface: Allow programs to interact with various devices
using standard commands.
CREATED BY K. VICTOR BABU
Types of I/O Devices
• I/O Devices are mainly divided into three types:
1. Input Devices
• Devices that send data to the computer.
Examples: Keyboard, Mouse, Scanner, Microphone
2. Output Devices
• Devices that receive data from the computer.
Examples: Monitor, Printer, Speakers
3. Input/Output (I/O) Devices
• Devices that can both send and receive data.
Examples: Touch Screen, Hard Disk, Pen Drive, Network Card
CREATED BY K. VICTOR BABU
Characteristics of I/O Devices
• I/O devices vary widely, so the Operating System must understand and
handle these differences. Here are the key characteristics:
• 1. Speed (Data Transfer Rate)
Definition: The rate at which data can be transferred between the device and
the system.
Example: A hard disk may transfer data at 100 MB/s, while a keyboard sends
just a few bytes per second.
2. Data Transfer Modes
•Character-based: Data is transferred one character at a time (e.g., keyboard).
•Block-based: Data is transferred in blocks (e.g., hard disks)

CREATED BY K. VICTOR BABU


Characteristics of I/O
Devices(Contd..)
3. Direction of Data Flow
Input Devices: Send data to the system (e.g., mouse, scanner).
Output Devices: Receive data from the system (e.g., printer, monitor).
•Input/Output Devices: Can do both (e.g., hard disk, touchscreen).
4. Access Method
Sequential Access: Data is read/written in order (e.g., magnetic tape).
Random Access: Any block of data can be accessed directly (e.g., hard
drive).

CREATED BY K. VICTOR BABU


6. Error Handling
• Devices may generate errors due to hardware failure, data corruption,
or user interruption.
OS Role: Detects, logs, and attempts to correct errors, or notifies the
user/program.

CREATED BY K. VICTOR BABU


THANK YOU

CREATED BY K. VICTOR BABU

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy