Chapter 2,3 Extra
Chapter 2,3 Extra
Once all the jobs get available in the ready queue, the algorithm will behave as
non-preemptive priority scheduling, which means the job scheduled will run till the
completion and no preemption will be done.
Chapter 3
Deadlocks:Definition
After some time, P1 demands for R1 which is being used by P2. P1 halts its
execution since it can't complete without R2. P2 also demands for R3 which is
being used by P3. P2 also stops its execution because it can't continue without R3.
P3 also demands for R1 which is being used by P1 therefore P3 also stops its
execution.
In this scenario, a cycle is being formed among the three processes. None of the
process is progressing and they are all waiting. The computer becomes
unresponsive since all the processes got blocked.
Deadlock Prevention
Deadlock Prevention and Avoidance is the one of the methods for handling
deadlock.
In deadlock prevention the aim is to not let fulfill one of the required condition of
the deadlock. This can be done by this method:
We only use the Lock for the non-shareable resources and if the resource is
shareable (like read only file) then we not use the locks here. That ensure that in
case of shareable resource , multiple process can access it at same time.
Problem- Here the problem is that we can only do it in case of shareable
resources but in case of no-share-able resources like printer , we have to use
Mutual exclusion.
To ensure that Hold and wait never occurs in the system, we must guarantee
that whenever process request for resource , it does not hold any other resources.
we can provide the all resources to the process that is required for its execution
before starting its execution .
For example if there are three resource that is required by a process and we
have given all that resource before starting execution of process then there might
be a situation that initially we required only two resource and after one hour we
want third resources and this will cause starvation for the another process that
wants this resources and in that waiting time that resource can allocated to other
process and complete their execution.
We can ensure that when a process request for any resources that time the process
does not hold any other resources.
Ex- Let there are three resources DVD, File and Printer . First the process request
for DVD and File for the copying data into the file and let suppose it is going to
take 1 hour and after it the process free all resources then again request for File
and Printer to print that file.
(iii) No Preemption
If a process is holding some resource and requestion other resources that are
acquired and these resource are not available immediately then the resources that
current process is holding are preempted. After some time process again request
for the old resources and other required resources to re-start.
For example – Process p1 have resource r1 and requesting for r2 that is hold by
process p2. then process p1 preempt r1 and after some time it try to restart by
requesting both r1 and r2 resources.
To remove the circular wait in system we can give the ordering of resources in
which a process needs to acquire.
Ex: If there are process p1 and p2 and resources r1 and r2 then we can fix the
resource acquiring order like the process first need to acquire resource r1 and
then resource r2. So the process that acquired r1 will be allowed to acquire r2 ,
other process needs to wait until r1 is free.
This is the Deadlock prevention methods but practically only fourth method is
used as all other three condition removal method have some disadvantages with
them.
Deadlock Avoidance
Avoidance is kind of futuristic. By using the strategy of “Avoidance”, we have to
make an assumption. We need to ensure that all information about resources that
the process will need is known to us before the execution of the process. We use
Banker’s algorithm to avoid deadlock.
In prevention and avoidance, we get the correctness of data but performance
decreases.
Deadlock Detection
This approach let the processes fall in deadlock and then periodically check
whether deadlock occur in the system or not. If it occurs then it applies some of the
recovery methods to the system to get rid of deadlock.