CS201 OPERATING SYSTEMS (FALL 2005) SOLUTIONS TO ASSIGNMENT4 Note: The following is only for reference. Some questions have several acceptable answers. 8.4(10 pts) Consider the lines of cars moving in one direction as processes, and intersections as resources. So, for the example in Figure 8.8: a) Mutual exclusion: There is a car at each intersection which cannot allow for a car of another line of cars. Hold and wait: Each line of cars is holding one intersection and waiting for another intersection. No preemption: An intersection cannot be freed unless the car holding it passes through. Circular wait: There are four lines of cars. Each blocks an intersection, and waits for an intersection to be freed by another line of cars. b) A car never blocks an intersection: It uses an intersection if and only if it passes through completely. 8.5(10pts) Consider such a system which only has one instance of resource A and one instance of resource B. P1 is holding A and waiting for B. P2 is holding B and waiting for A. There exists no safety sequence. But say P1 is a real-time process whose priority is higher than P2 which is a reading-filling process. P1 preempts P2’s B, then when P1 finishes, it releases all resources it has. P2 can complete. (Note: P1 and P2 are not in the deadlock state at the beginning because “no preemption” condition is not preserved in this system) 8.6(10 pts) a,d,f can be done safely under any circumstances. b,c,e sometimes can be done safely. 8.8(10pts) Suppose the system is deadlocked. This implies that each process is holding one resource and is waiting for one more. Since there are three processes and four resources, one process must be able to obtain two resources by pigeon-hole principle. This process requires no more resources, and therefore it will return its resources when done. Hence any circular wait involving 2,3, or 4 processes will be destroyed when one of the processes involved finishes. 1 8.13(10pts) a) Need is the following matrix: A B C D P0 0 0 0 0 P1 0 7 5 0 P2 1 0 0 2 P3 0 0 2 0 P4 0 6 4 2 b) Yes. P0, P2, P1, P3, P4 can execute, and finish in this order. c) Yes. The resulting system is safe as P0, P2, P1, P3, P4 can execute and finish in this order. 9.5(10 pts) First-fit: 212K is put in 500K partition 417K is put in 600K partition 112K is put in 288K partition (new partition for 288K = 500K – 212K) 426K must wait Best-fit: 212K is put in 300K partition 417K is put in 500K partition 112K is put in 200K partition 426K is put in 600K partition Worst-fit: 212K is put in 600K partition 417K is put in 500K partition 112K is put in 388K partition 426K must wait In this example, it turns out that Best-fit makes the most efficient use of memory. 9.10(10 pts) a) 400 nanoseconds: 200 nanoseconds to access the page table and 200 nanoseconds to access the word in memory. b) Effective access time = 0.75 x (200 nanoseconds) + 0.25 x (400 nanoseconds) = 250 nanoseconds. 2 9.13(10 pts) a) Segments are shared when entries in the segment tables of different processes point to the same physical location. b) All processes which want to share a segment (the same physical location)must define the shared code segment to have the same segment number. 10.8(10 pts) (0.99*1microsecond)+(0.01*0.8*2microseconds)+..+(0.1*0.2*0.5*1002 microseconds)+(0.01*0.2*0.5*2002microseconds) 10.11(10 pts) Number of frames LRU 1 20 2 18 3 15 4 10 5 8 6 7 7 7 FIFO 20 18 16 14 10 10 7 Optimal 20 15 11 8 7 7 7 10.16(10 pts) a) 1. 0 2. When a page contained in the page frame is replaced or is used , the counter belonging to that frame is increased. 3.When a page contained in the page frame is not used, the counter of that frame is decreased. 4.The page contained in the frame with the smallest counter is selected to be replaced. b) 14 page faults c) 11 page faults 3