You are on page 1of 3

Consider a system with five processes P0 through P4 and three resource types A,B, and C.

Resource type A has 10 instances, resource type B has 5 instances, and resource type C has 7 instances. Suppose that, at time T0, the following snapshot of the system has been taken: Allocation A B C 0 1 0 2 0 0 3 0 2 2 1 1 0 0 2 Max A B C 7 5 3 3 2 2 9 0 2 2 2 2 4 3 3 Available A B C 3 3 2

P0 P1 P2 P3 P4 i) ii)

Find the need matrix Check whether a system is currently in safe state or not?

The content of the Matrix need is defined to be Max allocation and is as follows: Max A B C 7 5 3 3 2 2 9 0 2 2 2 2 4 3 3 Allocation A B C 0 1 0 2 0 0 3 0 2 2 1 1 0 0 2 Need A B C 7 4 3 1 2 2 6 0 0 0 1 1 4 3 1

P0 P1 P2 P3 P4

Sequence of Resource allocation: Need A B C 7 4 3 1 2 2 6 0 0 0 1 1 4 3 1 the system is in safe state and the safe sequence is P1P3P4P0P2 , 3 1 4 2 5

P0 P1 P2 P3 P4

How to find sequence : Need A B C 7 4 3 1 2 2 6 0 0 0 1 1 4 3 1 Available A B C 3 3 2

P0 P1 P2 P3 P4

Here at time t0 the currently available resource is 3 instances of A, 3 instances of B and 2instances of C (3,3,2) Step1: The need for process P0 is (7,4,3). Check whether need for process P0 i.e need0available, (i.e, (7,4,3)(3,3,2)) the condition is false so go to next process. Step2: The need for process P1 is (1,2,2). Check whether need for process P1 i.e need1available, (i.e, (1,2,2)(3,3,2)) the condition is true. Now mark it as 1. Process P1 after completing its execution. It return backs its already allocated resource to the system.. that allocated resource of process P1 is added with the currently available resource which is (3,3,2). After adding allocated resource of P1 to already available resource now the currently available resource becomes (3,3,2)+(2,0,0)=(5,3,2) which is now the newly available resource. Step3: The need for process P2 is (6,0,0). Check whether need for process P0 i.e need2 new available, (i.e (6,0,0)(5,3,2)) the condition is false. So go to next process. Step4: The need for process P3 is (0,1,1). Check whether need for process P0 i.e need2 new available, (i.e (0,1,1)(5,3,2)) the condition is true. Now mark it as 2. Process P3 after completing its execution. It return backs its already allocated resource to the system.. that allocated resource of process P3 is added with the currently available resource which is (5,3,2). After adding allocated resource of P3 to already available resource now the currently available resource becomes (5,3,2)+(2,1,1)=(7,4,3) which is now the newly available resource. Step5: The need for process P4 is (4,3,1). Check whether need for process P4 i.e Need4 new available, (i.e (4,3,1)(7,4,3)) the condition is true. Now mark it as 3. Process P4 after completing its execution. It return backs its already allocated resource to the system.. that allocated resource of process P4 is added with the currently available resource which is (7,4,3). After adding allocated resource of P4 to already available resource now the currently available resource becomes (7,4,3)+(0,0,2)=(7,4,5) which is now the newly available resource. Step5: Once again come back to the left out processes starting from P0 to P4 we have 2 remaining processes. (i.e P0 and P2)

The need for process P0 is (7,4,3). Check whether need for process P4 i.e Need0 new available, (i.e (7,4,3)(7,4,5)) the condition is true. Now mark it as 4. Process P0 after completing its execution. It return backs its already allocated resource to the system.. that allocated resource of process P0 is added with the currently available resource which is (7,4,5). After adding allocated resource of P0 to already available resource now the currently available resource becomes (7,4,5)+(0,1,0)=(7,5,5) which is now the newly available resource. Step6: The need for process P2 is (6,0,0). Check whether need for process P4 i.e Need0 new available, (i.e (6,0,0)(7,5,5)) the condition is true. Now mark it as 5. Process P0 after completing its execution. It return backs its already allocated resource to the system.. that allocated resource of process P0 is added with the currently available resource which is (7,5,5). After adding allocated resource of P0 to already available resource now the currently available resource becomes (7,5,5)+(3,0,2)=(10,5,7) which is now the newly available resource. Therefore the system is in safe state and the safe sequence for process execution is P1P3P4P0P2 ,

You might also like