05.08.2013 Views

Module 6: Resource Sharing and Management - E-Courses

Module 6: Resource Sharing and Management - E-Courses

Module 6: Resource Sharing and Management - E-Courses

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Operating Systems Prof. P. C. P. Bhat<br />

Indian Institute of Science Bangalore<br />

Operating Systems/<strong>Resource</strong> <strong>Sharing</strong> <strong>and</strong> <strong>Management</strong> Worked out Examples<br />

Worked out Examples<br />

6.1 Consider a system consisting of 4 resources of same type that are share by 3<br />

processes each of which needs at most two resources. Show that the system is<br />

deadlock free<br />

Ans:<br />

If the system is deadlocked, it implies that each process is holding one resource<br />

<strong>and</strong> is waiting for one more. Since there are 3 processes <strong>and</strong> 4 resources, one<br />

process must be able to obtain two resources. This process requires no more<br />

resources <strong>and</strong> therefore it will return its resources when done.<br />

6.2 Consider a system with m resources of same type being shared by n<br />

processes. <strong>Resource</strong>s can be requested <strong>and</strong> released by processes only on at a<br />

time. The system is deadlock free if <strong>and</strong> only if<br />

a. The sum of all max needs is < m+n<br />

b. The sum of all max needs is > m+n<br />

c. Both of above<br />

d. None<br />

Ans: a<br />

6.3 A proposed solution to the Dining Philosophers deadlock problem is as<br />

follows:<br />

Philosopher( int i ) {<br />

while(1) {<br />

think();<br />

// grab forks if we can<br />

lock.P()<br />

fork[i].P();<br />

fork[(i+1)%5].P();<br />

lock.V();<br />

eat();<br />

// put down forks<br />

lock.P();<br />

fork[i].V();<br />

P.C.P.Bhat/IISc Bangalore M6/V1/June 04/1

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!