Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 10

Operating System

Assignment No.2

Lecturer’s Name: Ammarah

Student Name:
Resham Amanat
Nowal Zaman

Student Roll No: 18260819-019


18260819-026

Degree: Masters in Computer Science

3rd
Semester:
Deadlocks
An impasse is a situation in which a set of processes is blocked, because each process has a resource
and waits for another resource to be acquired by another process. Cite an example where two paths
come to each other on the same track and on the same track, when the two paths come up against each
other. The same situation occurs in systems that are active when there are two or more systems that
are running certain resources and waiting for host processes. For example, in the diagram below,
Process 1 holds Source 1 and waits for Source 2 obtained by Procedure 2, and Process 2 waits for
Source 1.

System Model

 To discourage negotiation, a system can be shaped as a collection of limited resources, which


can be divided into different categories, assigned to different processes, each with different
needs.
 Memory, printers, CPU, open files, tapes, CD-ROMs, etc. Be included in the resource
categories.
 According to the specification, all devices in the group are equal and request this type. If this is
not the case (that is, if there is a difference between the resources in the group), the part will be
divided into separate parts. For example, a "laser printer" can be classified as an "inkjet printer."
 Some groups will have the same location.
 In normal operation a process must be executed before requesting a source, and when it is done,
release in the following rule:
1. Request-If the request cannot be granted immediately, the process must wait for the
necessary resources. For example, the system calls open (), malloc (), new (), request ()
2. Use a source-based process, such as authorizing printing or reading from a file.
3. Released - the release of resources. So, will become available for other road. For example,
close( ), free( ), delete( ), and release( ).
 For all kernel-managed resources, the kernel is responsible for the free and downloaded
resources, the way they are allocated and queued under this system. Managed resources can be
managed by shortcuts or wait () and dial () dials (i.e. double digits or sea counts).
 When each process in a group is waiting for resources in the resource that are currently
assigned to other processes in the group, a group of processes will be blocked (and will only be
released when other pending processes are progressing.)

Deadlock Prevention

Deadlocks can be prevented by preventing a minimum of four of the following conditions:

Mutual Exclusion

 Shared resources (such as read-only files) do not cause deadlocks.


 Unfortunately, some sources, such as printers and tape drives, require exclusive access in a
single process.

Hold and Wait

 At the same time, while waiting for one or more of the other conditions of these processes, with
one or more means for prevention must be prevented. There are various options for this:
o Require that all processes request all resources at one time. This can be wasteful of system
resources if a process needs one resource early in its execution and doesn't need some other
resource until much later.
o Require that processes holding resources must release them before requesting new resources,
and then re-acquire the released resources along with the new ones in a single new request.
This can be a problem if a process has partially completed an operation using a resource and
then fails to get it re-allocated after releasing it.
o Either of the methods described above can lead to starvation if a process requires one or
more popular resources.

No Preemption

 Preemption of process resource allocations can prevent this condition of deadlocks, when it is
possible.
o One approach is that if a process needs to wait for a new resource, then all other resources
previously owned by the process are implicitly released and reused. with new resources in
one request, similar to the previous discussion.
o Another way is when the resource is requested and the resource is not available, the system
will see which resources are currently in the other processes, and they will be blocked and
waiting for other resources. If such a process is found, some of their resources may be
exhausted ahead of time and added to the list of resources that the process is waiting for.
o Each of these methods may be suitable for resources that can be easily stored and restored,
such as logs and memory, but generally not for other devices, such as printers and tape
drives.

Circular Wait

 One way to avoid waiting for circulation is to count all resources and ask the process of
requesting resources with orders that are increasing strictly (or decreasing).
 In other words, to request a resource Rj, a process must first release all Ri so that i> = j.
 A major challenge in this scheme is to determine the relative order of the various sources
Deadlock Avoidance

Deadlock avoidance can be done with Banker’s Algorithm.

Banker’s Algorithm

The bank's algorithm is a resource allocation and avoidance algorithm that tests all requests for
resource processes, checks the secure state, if it stays in the safe state after granting the request
system, allows the request and if there is not secure state, the process request does not allow.

Inputs to Banker’s Algorithm:

1. Maximum need for resources for each process.


2. Currently allocated resources through each process.
3. Maximum Free system resources.
The request will only be granted under the below condition:
1. If the demand for the process is less than the maximum need for that process.
2. If the process request is less than equal to the freely available source in the system.
Example:

Total resources in system:


ABCD
6576
Available system resources are:
ABCD
3112
Processes (currently allocated resources):
A B C D
P1 1 2 2 1
P2 1 0 3 3
P3 1 2 1 0
Processes (maximum resources):
A B C D
P1 3 3 2 2
P2 1 2 3 4
P3 1 3 5 0
Need = maximum resources - currently allocated resources.
Processes (need resources):
A B C D
P1 2 1 0 1
P2 0 2 0 1
P3 0 1 4 0

Deadlock Detection

 If deaths are not preventable, another approach is to detect when they occurred and to recover in
one way or another.
 In addition to the successful performance of constantly monitoring deadlines, policy / algorithm
needs to be repairable, and there may be a loss of work when processes need to be interrupted or
their resources hampered.

Single Instance of Each Resource Type

 If each source category has one example, we can use a variation of the resource allocation graph,
queue.
 An expectation graph can be constructed from a resource allocation resource by deleting the
resources and collapsing the corresponding boundaries, as shown in the image.
 An arc of Pi to Pj in an expectation graph indicates that a process Pi expects a resource that
currently holds a process Pj.
(a) Resource allocation graph. (b) Corresponding wait-for graph

 As before, loops in the waiting graph indicate deaths.


 This algorithm must keep track of the wait graph and periodically search for cycles.

Several Instances of a Resource Type

 The detection algorithm described here is essentially the same as the Banker's algorithm, with
two subtle differences:
o In step 1, the Banker's algorithm sets End [i] to false for all i. The algorithm presented here
only sets Finish [i] to false if Allocation [i] is not zero. If the currently allocated resources for
this process are zero, the Finish [i] algorithm is set to true. This basically assumes that ALS all
other processes can be completed, this process can also be terminated. Moreover, this
algorithm specifically looks for which processes are involved in a dead block and a process
that does not have allocated resources cannot be involved in a dead block and therefore can be
taken away from some other consideration.
o Steps 2 and 3 are unchanged
o In step 4, the basic banking algorithm says that if Finish [i] == is true for all i, there is no
impasse. This algorithm is more specific, stating that if Finish [i] == is false for process Pi,
that process specifically deals with the detected deadline.
 An alternative method was introduced above, where Finish was kept as an integer instead of a
boolean. This vector is reset to all zeros and filled with incremental integers as processes that may
end are detected. If processes are left at zero when the algorithm is completed, the deadlock will
be, and if not, integers will describe the safe sequence. To adjust this algorithm to this part of the
text, processes that are set to zero can be executed with N, N - 1, N - 2, and so on. Stage 1 and all
processes in Stage 4 Finish = 0 are: Crash processes.
 Consider, for example, the following status and determine if it is now deadlock:

 Now suppose that process P2 sends a request for an additional copy of type C, which gives the
status shown below. Has the system crashed now?
Deadlock Recovery

 There are three basic approaches to recovery from deadlock:


1. Inform the management system and let him intervene manually.
2. Complete one or more processes involved in the deadlock
3. Preempt resources.

Process Termination

 Two basic approaches that restore resources assigned to completed processes:


o Complete all processes involved in deadlock. This certainly fixes the downside, but at the cost
of finishing more processes than would be absolutely necessary.
o End process one after the other until the break is broken. This is more conservative, but
requires undetectable detection after each step.
 In the latter case, there are many factors that can play a role in determining the following
processes:
1. Process priorities.
2. How long the process has worked and how close it ends.
3. How long the process worked and how close it ends.
4. How many resources does the process still have to complete?
5. How many processes must be completed
6. Whether the process is interactive or batch.
7. Has the process made non-rechargeable changes to a resource.

Resource Preemption

 There are three main issues that need to be addressed when preventing deadly significance:
1. Selecting a victim - In deciding which means to avoid from which processes, many of the
same decision criteria described above are needed.
2. Rollback - Ideally, one would want to return a previous process to a safe state before the
point at which that source was originally allocated to the process. Unfortunately, it can be
difficult or impossible to determine what such a safe state is, and so the only safe way back is
before the start. (Somewhere to abolish the process and get started.)
3. Starvation - How can we ensure that the process does not starve because its resources are
constantly being constrained? It would be possible to use a prioritization system and increase
the priority of the process if resources fail. Ultimately, it should be given a high enough
priority that it cannot be achieved.

You might also like