Module-5
Module-5
(Autonomous)
Dundigal, Hyderabad - 500 043
Module-V
DEADLOCKS
by
1
System model: Deadlock characterization
• Circular Wait
• A process is waiting for the resource held by the second process,
which is waiting for the resource held by the third process and so
on, till the last process is waiting for a resource held by the first
process. This forms a circular chain. For example: Process 1 is
allocated Resource2 and it is requesting Resource 1. Similarly,
Process 2 is allocated Resource 1 and it is requesting Resource 2.
This forms a circular wait loop.
System model: Deadlock characterization
Mutual Exclusion
There should be a resource that can only be held by one
process at a time. In the diagram below, there is a single
instance of Resource 1 and it is held by Process 1 only.
System model: Deadlock characterization
No Preemption
A resource cannot be preempted from a process by force. A
process can only release a resource voluntarily. In the
diagram below, Process 2 cannot preempt Resource 1 from
Process 1. It will only be released when Process 1
relinquishes it voluntarily after its execution is complete.
INSTITUTE OFAERONAUTICAL ENGINEERING
(Autonomous)
Dundigal, Hyderabad - 500 043
Module-V
DEADLOCKS
by
1
Methods of handling deadlocks
1. Deadlock Ignorance
Deadlock Ignorance is the most widely used approach
among all the mechanism. This is being used by many
operating systems mainly for end user uses.
In this approach, the Operating system assumes that
deadlock never occurs. It simply ignores deadlock. This
approach is best suitable for a single end user system
where User uses the system only for browsing and all
other normal stuff
Methods of handling deadlocks
Deadlock Prevention
Deadlock happens only when Mutual Exclusion, hold
and wait, No preemption and circular wait holds
simultaneously. If it is possible to violate one of the
four conditions at any time then the deadlock can
never occur in the system.
3. Deadlock avoidance
In deadlock avoidance, the operating system checks
whether the system is in safe state or in unsafe state at
every step which the operating system performs. The
process continues until the system is in safe state. Once
the system moves to unsafe state, the OS has to backtrack
one step.
1. Mutual Exclusion
Mutual section from the resource point of view is the fact
that a resource can never be used by more than one
process simultaneously which is fair enough but that is
the main reason behind the deadlock.
Spooling
Later, Printer collects all the jobs and print each one of them
according to FCFS. By using this mechanism, the process
doesn't have to wait for the printer and it can continue
whatever it was doing. Later, it collects the output when it is
produced
Deadlock Prevention
Hold and wait condition lies when a process holds a resource and
waiting for some other resource to complete its task. Deadlock
occurs because there can be more than one process which are
holding one resource and waiting for other in the cyclic order.
!(Hold and wait) = !hold or !wait (negation of hold and wait is, either
you don't hold or you don't wait)
3. No Preemption
Deadlock arises due to the fact that a process can't be stopped
once it starts. However, if we take the resource away from the
process which is causing deadlock then we can prevent
deadlock.
This is not a good approach at all since if we take a resource
away which is being used by the process then all the work which
it has done till now can become inconsistent.
Consider a printer is being used by any process. If we take the
printer away from that process and assign it to some other
process then all the data which has been printed can become
inconsistent and ineffective and also the fact that the process
can't start printing again from where it has left which causes
performance inefficiency.
Deadlock Prevention
4. Circular Wait
To violate circular wait, we can assign a priority number to each
of the resource. A process can't request for a lesser priority
resource. This ensures that not a single process can request a
resource which is being utilized by some other process and no
cycle will be formed.
Among all the methods, violating Circular wait is the only approach that can be
implemented practically.
INSTITUTE OFAERONAUTICAL ENGINEERING
(Autonomous)
Dundigal, Hyderabad - 500 043
Module-V
DEADLOCKS
by
1
Methods of handling deadlocks
1. Deadlock Ignorance
Deadlock Ignorance is the most widely used approach
among all the mechanism. This is being used by many
operating systems mainly for end user uses.
In this approach, the Operating system assumes that
deadlock never occurs. It simply ignores deadlock. This
approach is best suitable for a single end user system
where User uses the system only for browsing and all
other normal stuff
Methods of handling deadlocks
Deadlock Prevention
Deadlock happens only when Mutual Exclusion, hold
and wait, No preemption and circular wait holds
simultaneously. If it is possible to violate one of the
four conditions at any time then the deadlock can
never occur in the system.
3. Deadlock avoidance
In deadlock avoidance, the operating system checks
whether the system is in safe state or in unsafe state at
every step which the operating system performs. The
process continues until the system is in safe state. Once
the system moves to unsafe state, the OS has to backtrack
one step.
1. Mutual Exclusion
Mutual section from the resource point of view is the fact
that a resource can never be used by more than one
process simultaneously which is fair enough but that is
the main reason behind the deadlock.
Spooling
Later, Printer collects all the jobs and print each one of them
according to FCFS. By using this mechanism, the process
doesn't have to wait for the printer and it can continue
whatever it was doing. Later, it collects the output when it is
produced
Deadlock Prevention
Hold and wait condition lies when a process holds a resource and
waiting for some other resource to complete its task. Deadlock
occurs because there can be more than one process which are
holding one resource and waiting for other in the cyclic order.
!(Hold and wait) = !hold or !wait (negation of hold and wait is, either
you don't hold or you don't wait)
3. No Preemption
Deadlock arises due to the fact that a process can't be stopped
once it starts. However, if we take the resource away from the
process which is causing deadlock then we can prevent
deadlock.
This is not a good approach at all since if we take a resource
away which is being used by the process then all the work which
it has done till now can become inconsistent.
Consider a printer is being used by any process. If we take the
printer away from that process and assign it to some other
process then all the data which has been printed can become
inconsistent and ineffective and also the fact that the process
can't start printing again from where it has left which causes
performance inefficiency.
Deadlock Prevention
4. Circular Wait
To violate circular wait, we can assign a priority number to each
of the resource. A process can't request for a lesser priority
resource. This ensures that not a single process can request a
resource which is being utilized by some other process and no
cycle will be formed.
Among all the methods, violating Circular wait is the only approach that can be
implemented practically.
Deadlock avoidance
1.E = (7 6 8 4)
2.P = (6 2 8 3)
3.A = (1 4 0 1)
• Above tables and vector E, P and A describes the
resource allocation state of a system. There are 4
processes and 4 types of the resources in a system.
Table 1 shows the instances of each resource
assigned to each process.
• A state of the system is called safe if the system can allocate all
the resources requested by all the processes without entering
into deadlock.
• If the system cannot fulfill the request of all processes then the
state of the system is called unsafe.
Example
Let’s consider 3 processes P1, P2 and P3, and two types of resources
R1 and R2. The resources are having 1 instance each.
According to the graph, R1 is being used by P1, P2 is holding R2 and
waiting for R1, P3 is waiting for R1 as well as R2.
The graph is deadlock free since no cycle is being formed in the
graph.
Resource Allocation Graph
Process R1 R2 R3
P1 0 0 1
P2 1 0 0
P3 0 1 0
Request Matrix
In request matrix, an entry will be made for each of the resource
requested. As in the following example, P1 needs R1 therefore an
entry is being made in front of P1 and below R1.
Process R1 R2 R3
P1 1 0 0 Aavial = (0,0,0)
P2 0 1 0
P3 0 0 1
Resource Allocation Graph
Module-V
DEADLOCKS
by
1
Preventing deadlock
1. Mutual Exclusion
Mutual section from the resource point of view is the fact
that a resource can never be used by more than one
process simultaneously which is fair enough but that is
the main reason behind the deadlock.
Spooling
Later, Printer collects all the jobs and print each one of them
according to FCFS. By using this mechanism, the process
doesn't have to wait for the printer and it can continue
whatever it was doing. Later, it collects the output when it is
produced
Deadlock Prevention
Hold and wait condition lies when a process holds a resource and
waiting for some other resource to complete its task. Deadlock
occurs because there can be more than one process which are
holding one resource and waiting for other in the cyclic order.
• Basic Facts
If a system is in safe state no deadlocks
Avoidance Algorithms
Resource-Allocation Graph
Deadlock Avoidance
Example
Let’s consider 3 processes P1, P2 and P3, and two types of resources
R1 and R2. The resources are having 1 instance each.
According to the graph, R1 is being used by P1, P2 is holding R2 and
waiting for R1, P3 is waiting for R1 as well as R2.
The graph is deadlock free since no cycle is being formed in the
graph.
Resource Allocation Graph
P1 0 0 1
P2 1 0 0
P3 0 1 0
Resource Allocation Graph
Request Matrix
In request matrix, an entry will be made for each of the
resource requested. As in the following example, P1
needs R1 therefore an entry is being made in front of P1
and below R1.
Process R1 R2 R3
P1 1 0 0
P2 0 1 0
P3 0 0 1
Resource Allocation Graph
Multiple instances
Module-V
Protection in Operating System
by
1
Protection in Operating System
•Typically each user is given their own account, and has only
enough privilege to modify their own files.
•The root account should not be used for normal day to day
activities - The System Administrator should also have an
ordinary account, and reserve use of the root account for only
those tasks which need the root privileges
Role of Protection in Operating System
• Fixed or static –
• In fixed association, all the access rights can be given to
the processes at the very beginning but that give rise to
a lot of access rights for domain switching.
• Changing or dynamic –
In dynamic association where a process can switch
dynamically, creating a new domain in the process, if
need be.
An Example: UNIX
•UNIX associates domains with users.
•Certain programs operate with the SUID bit set, which effectively
changes the user ID, and therefore the access domain, while the program
is running. ( and similarly for the SGID bit. ) Unfortunately this has
some potential for abuse.
•An alternative used on some systems is to place privileged programs in
special directories, so that they attain the identity of the directory owner
when they run. This prevents crackers from placing SUID programs in
random directories around the system.
•Yet another alternative is to not allow the changing of ID at all. Instead,
special privileged daemons are launched at boot time, and user processes
send messages to these daemons when they need special tasks
performed.
Domain of Protection in Operating System
An Example: MULTICS
The MULTICS system uses a complex system of rings, each
corresponding to a different protection domain, as shown below:
Module-V
Access matrix, implementation of
Access matrix
by
1
Access matrix, implementation of Access matrix
1.Global Table
2.Access Lists for Objects
3.Capability Lists for Domains
4.Lock-Key Mechanism
Access matrix, implementation of Access matrix
Global Table
• It is the most basic access matrix implementation.
• A set of ordered triples <domain, object, rights-
set> is maintained in a file.
• When an operation M has been performed on an
object Oj within domain Di, the table is searched for
a triple <Di, Oj, Rk>.
• The operation can proceed if this triple is located;
otherwise, an exception (or error) condition has
arrived. This implementation has various drawbacks.
• The table is generally large and cannot be stored in
the main memory, so additional input and output are
required.
Access matrix, implementation of Access matrix
Lock-Key Mechanism
• It is a compromise between the access lists and the
capability lists.
• Each object has a list of locks, which are special bit
patterns. On the other hand, each domain has a set
of keys that are special bit patterns.
• A domain-based process could only access an
object if a domain has a key that satisfies one of the
locks on the object.
• The process is not allowed to modify its keys.
Access matrix, implementation of Access matrix
Module-V
Access matrix, implementation of
Access matrix
by
1
Access matrix, implementation of Access matrix
1.Global Table
2.Access Lists for Objects
3.Capability Lists for Domains
4.Lock-Key Mechanism
Access matrix, implementation of Access matrix
Global Table
• It is the most basic access matrix implementation.
• A set of ordered triples <domain, object, rights-
set> is maintained in a file.
• When an operation M has been performed on an
object Oj within domain Di, the table is searched for
a triple <Di, Oj, Rk>.
• The operation can proceed if this triple is located;
otherwise, an exception (or error) condition has
arrived. This implementation has various drawbacks.
• The table is generally large and cannot be stored in
the main memory, so additional input and output are
required.
Access matrix, implementation of Access matrix
Lock-Key Mechanism
• It is a compromise between the access lists and the
capability lists.
• Each object has a list of locks, which are special bit
patterns. On the other hand, each domain has a set
of keys that are special bit patterns.
• A domain-based process could only access an
object if a domain has a key that satisfies one of the
locks on the object.
• The process is not allowed to modify its keys.
Access matrix, implementation of Access matrix
Module-V
Access control, revocation of access
rights
by
1
Access control, revocation of access rights
Hydra
Fixed set of access rights known to and interpreted by the system
i.e. read, write, or execute each memory segment
User can declare other auxiliary rights and register those with
protection system
Accessing process must hold capability and know name of
operation
Rights amplification allowed by trustworthy procedures for a
specific type
Interpretation of user-defined rights performed solely by user's
program; system provides access protection for use of these rights
Operations on objects defined procedurally – procedures are
objects accessed indirectly by capabilities
Solves the problem of mutually suspicious subsystems
Includes library of prewritten security routines
Capability-Based Systems