You are on page 1of 4

Assignment-3

SUBMITTED TO: SUBMITTED BY:


MR.SHARABJEET KUMAR REENA CHOUDHURY
RE3801A27
BCA-MCA
Is it possible to have a deadlock involving only one single process? Explain your answer with an
example.

ANSWER:- :- It is not possible to have a deadlock involving only one single process. A
processes requests resources if the resources are not available are not available at that
time ,the processes enter a wait state.In a multiprogramming environment, several processes
may compete for a finite number of resources. The deadlock involves a circular “hold-and-
wait” condition between two or more processes, so “one” process cannot hold a resource,
yet be waiting for another resource that it is holding.

In addition, deadlock is not possible between two threads in a process, because it is the
process that holds resources, not the thread that is, each thread has access to the resources
held by the process .In deadlock , processes never finish executing and system resources are
tied up, preventing other jobs from starting .a set of processes is in a deadlock state for eg-
consider a system with one printer and one tape driver.suppose that processes pi iis holding
the tape driver and processes pj is holding the printer.

when every process in the set is waiting for an event that can be caused only f pi is
requested the printer and pj request the tape driver ,a deadlock occur

Consider the traffic deadlock

a) Show that the four necessary conditions for deadlock indeed held in this example. b) State a
simple rule that will avoid deadlock in this system.

ANSWER:- A deadlock situation can arise if the following four conditions


hold simultananeousely in a system:

(a)
Mutual exclusion .At least one resorce must be held in a non sharable mode that is only one
process at a time can use the resource. The condition applies, since only one vehicle can be on a section
of the street at a time.

Hold-and-wait – a process must be holding at least one resource and waiting to acquire other
processes .The condition applies, since each vehicle is occupying a section of the street, and waiting to
move on to the next section of the street.

Non-premptive-: Resource can’t be preempted i.e. the resource can be released only voluntarily by
the process holding it after the process has completed its task.

Circular wait-:A set {po,p1…,pn} of waiting process must exist such that po is waiting for a
resorce that is held by p1,p1 is waiting for resource is held by p2,pn-1. The condition applies, since
each vehicle is waiting on the next vehicle to move. That is, each vehicle in the traffic is waiting for a
section of street held by the next vehicle in the traffic.

(b) we can avoid deadlock by -

DEADLOCK AVOIDENCE-: The restraints ensure that atleast one of the necessary
condition for deadlock can’t occur and hence deadlock can’t hold. operating system be given in
advance additional information concerning which resource a process will request and used
during its life time.

A state is safe if the system can allocate resource to each process In some order
and still avoid the deadlock.More formally a system is in safe state only if there
exist in a safe sequence

Consider the following snapshot of a system

Allocation Max Available

ABCD ABCD ABCD

P0 0 01 2 0012 1520

P1 1000 1750

P2 1354 2356

P3 0632 0652

P4 0 01 4 0656
Answer the following questions using Banker’s Algorithm
What are the contents of Matrix Needed?
Is this system in a safe state?
If a request from process P1 arrives for (0 4 2 0), Can the request be granted immediately?

ANSWER:- a.The contents of matrix needed-:

Since Need = Max - Allocation, the content of Need is

ABCD

0000

0750

1002

0020

0642

b.The whole system is in safe state-:<p0,p1,p2,p3,p4>

c.Yes ,a request from process p1 can be granted immedietly.

I. (0, 4, 2, 0) <= Available = (1, 5,2,0)

ii. (0,4,2,0) <= Max_i = (1,7,5,0)

iii. The new system state after the allocation is made is

Allocation Max Need Available

P0 0012 0012 0000 1100

P1 1420 1750 0330

P2 1354 2356 1002

P3 0632 06.52 0020

P4 0014 0656 0642

And the sequence < P0, P2, P1, P3, P4 > satisfies the safety requirement.

4.What is an unsafe state? Should we call a deadlock state to unsafe state?


ANSWER:- -: UNSAFE STATE-:An unsafe state may lead to deadlock. In an unsafe
state, the operating system can’t prevent processes from requesting resources such that a
deadlock occurs. The behavior of the processes control unsafe states. A system may go
from safe state to unsafe state. The state is safe, the operating system can avoid unsafe.

If the resources that process pi needs are not immediately available then p1 can wait until
all pj have finished.

When they have finished, pi can obtain all of its needed resources, complete its designated
task, return its allocated resource, and terminate. When pi terminates, pi+1 can obtain its
needed resource, and so on. If no such sequence exists, then the system state is said to be
unsafe.

Not, all unsafe state are deadlock.A state is unsafe when the operating system can’t
prevent processes from requesting resources