Professional Documents
Culture Documents
OS Assignment 2
OS Assignment 2
Assignment No.2
Student Name:
Resham Amanat
Nowal Zaman
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
Deadlock Prevention
Mutual Exclusion
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
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.
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.
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
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
Process Termination
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.