Assignment No 2 & Linux and (CSE-A and IT) IV Sem 1. Give examples of a sharable resources and a non-sharable resource in a computer system. 2. What is and critical section problem? How we can avoid that issues. 3. Write down the differences between a. and Monitor b. Deadlock prevention and avoidance c. Hold and wait and No Preemption 4. Servers can be designed to limit the number of open connections. For example, a server may wish to have only N socket connections at any point in time. As soon as N connections are made, the server will not accept another incoming connection until an existing connection is released. Explain how semaphores can be used by a server to limit the number of concurrent connections. 5. The Sleeping-Barber Problem. A barbershop consists of a waiting room with n chairs and a barber room with one barber chair. If there are no customers to be served, the barber goes to sleep. If a customer enters the barbershop and all chairs are occupied, then the customer leaves the shop. If the barber is busy but chairs are available, then the customer sits in one of the free chairs. If the barber is asleep, the customer wakes up the barber. Write a program to coordinate the barber and the customers. 6. Consider the dining-philosophers problem where the chopsticks are placed at the center of the table and any two of them could be used by a philosopher. Assume that requests for chopsticks are made one at a time. Describe a simple rule for determining whether a particular request could be satisfied without causing deadlock given the current allocation of chopsticks to philosophers.

7. Consider the following resource allocation state snapshot of a system with 5 processes (p0, p1, p2, p3, p4) and 4 resource types (A, B, C, and D):

allocation max need available

A B C D A B C D A B C D A B C D

p0 1 0 2 0 3 2 4 2 3 4 0 1

p1 0 3 1 2 3 5 1 2

p2 2 4 5 1 2 7 7 5

p3 3 0 0 6 5 5 0 8

p4 4 2 1 3 6 2 1 4

 Fill in all entries of the need matrix above.  Is the system in a safe state?

 Can a (0,4,0,1) request from process p3 be granted immediately? 8. A single-lane bridge connects the two Vermont villages of North Tunbridge and South Tunbridge. Farmers in the two villages use this bridge to deliver their produce to the neighboring town. The bridge can become deadlocked if both a northbound and a southbound farmer get on the bridge at the same time (Vermont farmers are stubborn and are unable to back up.) Using semaphores, design an that prevents deadlock. Initially, do not be concerned about starvation (the situation in which northbound farmers prevent southbound farmers from using the bridge or vice versa).