0% found this document useful (0 votes)
60 views1 page

Assignment No. 3 Muhammad Faizan Karim (MC110402217) : (Solution)

The document describes the data structures and algorithm for the banker's algorithm to determine if a system is in a safe state. It outlines the need vector, max matrix, allocation matrix, available vector, and work and finish vectors. The algorithm initializes work to available, then finds a process i that can run by checking if its need is less than work. It updates work by subtracting i's allocation, and marks i as finished if it can run. It repeats until all processes are marked finished, indicating the system is safe.

Uploaded by

faizan.kareem
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
60 views1 page

Assignment No. 3 Muhammad Faizan Karim (MC110402217) : (Solution)

The document describes the data structures and algorithm for the banker's algorithm to determine if a system is in a safe state. It outlines the need vector, max matrix, allocation matrix, available vector, and work and finish vectors. The algorithm initializes work to available, then finds a process i that can run by checking if its need is less than work. It updates work by subtracting i's allocation, and marks i as finished if it can run. It repeats until all processes are marked finished, indicating the system is safe.

Uploaded by

faizan.kareem
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 1

CS604-operating Systems

Assignment No. 3 Muhammad Faizan Karim(MC 040!! "#

(Solution) Several data structures must be maintained to implement the bankers algorithm. These data structures encode the state of the resource-allocation system. Let n be the number of processes in the system and m be the number of resource types. We need the following data structures: . Available: ! vector of length m indicates the number of available resources of each type. "fAvailable[j]=k# there are k instances of resource type Rj available. $. Max: !n nm matri% defines the ma%imum demand of each process. "f Max [i,j]=k# then process Pi may re&uest at most k instances of resource type Rj. '. Allocation: !n nm matri% defines the number of resources of each type currently allocated to each process. "f Allocation [i,j]=k# then process Pi is currently allocated k instances of resource type Rj. (. Need: !n nm matri% indicates the remaining resource need of each process. "f Need [i,j]=k# then process Pi may need k more instances of resource type Rj to complete its task. Need [i,j]=Max[i,j]-Allocation[i,j] The algorithm for finding out whether or not a system is in a safe state can be: Let Work and )inish be vectors of length m and n# respectively. "nitiali*e Work: =Available and Fini ! +i,:="al e for i=#,$,%,n . )ind an i such that both a& Fini !+i, ="al e b& Needi-Work "f no such i e%ists# go to step (. $. Work: =Work'Allocationi Fini !+i,:=tr(e go to step $. '. "f Fini !+i, =tr(e for all i# then the system is in a safe state. This algorithm may re&uire an order of mn) operations to decide whether a state is safe. .onsider the system with five processes /0 through /( and four resource types A, *, +, and ,. !llocated 0 $ 0 0 1eed 0 $ 0 0 ' !vailable 0 $ ' $ 3 ' $ 3 (

/rocess ! /rocess 2 /rocess . /rocess 4

0 0 0

0 0 0

0 0 0

$ 0 0

0 $ '

$ $

We claim that the system is currently in a safe state.

You might also like