Professional Documents
Culture Documents
DEPARTMENT OF CSE
ACADEMIC YEAR JUNE_SEPT_2023
INTERNAL ASSESSMENT TEST-II
SCHEME AND SOLUTION
b 2.5*2=5M
PAGE:
Subject Code:21CS44 Subject: Operating System
Q. MARKS
SOLUTION
NO. ALLOCATED
Q.2.a Schematic View of Monitor: A monitor type presents a set of programmer-defined 02+03=5M
operations that are provided mutual exclusion within the monitor. The monitor type
contains the declaration of variables whose values define the state of an instance of
that type and the bodies of procedures or functions that operate on those variables.
The representation of a monitor type cannot be used directly by the various
processes. Thus, a procedure defined within a monitor can access only those
variables declared locally within the monitor and its formal parameters.
PAGE:
Subject Code:21CS44 Subject: Operating System
Q. MARKS
SOLUTION
NO. ALLOCATED
Necessary Conditions
A deadlock situation can arise if the following four conditions hold simultaneously
in a system:
1. Mutual exclusion:
At least one resource must be held in a non-sharable mode; that is, only one
process at a time can use the resource. If another process requests that resource,
the requesting process must be delayed until the resource has been released.
2) Hold and Wait A process must be holding at least one resource and waiting to
acquire additional resources that are currently being held by other processes.
3) No Preemption Resources cannot be preempted. that is, a resource can be
released only voluntarily by the process holding it, after that process has completed
its task
4) Circular Wait A set of processes { P0, P1, P2, . . ., P n } waiting must exist such
that P0 is waiting for a resource that is held by P1 ,P1 is waiting for a resource that
is held by P2, ….Pn-1 is waiting for a resource held by P n, and Pn, is waiting for a
resource held by P0.
Case I : Cycle with Deadlock with all Resource Types having only 1-instance.
3.a
2.5*2=5M
Case 2:Cycle with No Deadlock with at least one Resource type having
multiple instances.
consider the resource-allocation graph in Figure
In this example, we also have a cycle P1 → R1 → P3→ R2 → P1
PAGE:
Subject Code:21CS44 Subject: Operating System
Q. MARKS
SOLUTION
NO. ALLOCATED
b. Assumptions:
2+3=5M
Let n = number of processes in the system
Let m = number of resources types.
• Following data structures are used to implement the banker‘s algorithm.
1) Available: - A vector of length m, indicates the no. of available resources of
each type. - If Available[j]=k, then k instances of resource type Rj is
available.
2) Max - an n X m matrix indicates the maximum demand of each process of
each resource. - If Max[i][j]=k, then process Pi may request at most k
instances of resource type Rj.
3) Allocation - an n X m matrix ,indicates no. of resources currently allocated
to each process. - If Allocation[i][j]=k, then Pi is currently allocated k
instances of Rj.
4) Need - an n X m matrix, indicates the remaining resources need of each
process. -If Need[i][j]=k, then Pi may need k more instances of resource Rj
to complete its task.
- So, Need[i][j] = Max[i][j] - Allocation[i][j]
Safety Algorithm
Algorithm to verify whether the system is safe (or) not after allocating the requested
resource
1. Let Work and Finish be vectors of length m and n, respectively. Initialize
Work = Available and Finish[i] =false for i= 0,1, ..., n-l.
2. Find an i such that both
a. Finish[i] ==false
b. Needi ≤ Work
If no such i exists, go to step 4.
3. Work = Work + Allocation, Finish[i] = true Go to step 2.
4. If Finish[i] = true for all. i then the system is in a safe state.
PAGE:
Subject Code:21CS44 Subject: Operating System
Q. MARKS
SOLUTION
NO. ALLOCATED
Step 1: Work=Available=1 0 2
Finish[i]=False for i=0,1,2,3…n
Step 2: Finish[i]=Finish[0]=P0==False True
Need[P0]<=work, 0 0 2<=1 0 2 True //(P0 Completes Execution
and Releases Resources)
Step 3: Work=work+ Allocation[P0]=1 0 2 + 0 0 2=1 0 4 Finish[i]=P0=True
PAGE:
Subject Code:21CS44 Subject: Operating System
Q. MARKS
SOLUTION
NO. ALLOCATED
If a request from p2 arrives for (0,0,,2)
To decide whether the request is granted, we use resource Request algorithm.
P0: Need[P0]<=work
0 0 2<=1 0 0 False
So P0 must wait
P1: Need[P1]<=work
1 0 1<=1 0 0 False
So P1 must wait
P2: Need[P2]<=1 0 0
0 0 0<=1 0 0 True
Work==work+ allocation[P2]=1 0 0+ 1 3 7=2 3 7
P3: Need[P3]<=work
2 1 0 <=2 3 7 True
Work=work+ Allocation[P3]=2 3 7+6 3 2=8 6 9
P4: Need[P4]<=work
0 1 4<=8 6 9 True
Work=work+ Allocation[P4]=8 6 9+1 4 3=9 10 12
P0: Need[P0] <=work
0 0 2<=9 10 12 True
Work=work+ Allocation[P0] =9 10 12+0 0 2=9 10 14
P1: Need[P1] <=work
1 0 1<=9 10 14 True
Work=work+ Allocation[P1] =9 10 14+0 0 2=9 10 16
PAGE:
The Request of P1 will be granted immediately.So safe sequence <P2,P3,P4,P0,P1>
Q. MARKS
SOLUTION
NO. ALLOCATED
5.a.
2+3=5M
Each element consists of three fields: (1) the virtual page number, (2) the value of
the mapped page frame, and (3) a pointer to the next element in the linked list.
PAGE:
Q. MARKS
SOLUTION
NO. ALLOCATED
The virtual page number is compared with field 1 in the first element in the
linked list. If there is a match, the corresponding page frame (field 2) is used
to form the desired physical address. if there is no match, subsequent entries
in the linked list are searched for a matching virtual page number.
PAGE: