COMP 3361: Operating Systems 1 Midterm Winter 2009 Name: Instructions This is an open book exam. The exam is worth 100 points, and each question indicates how many points it is worth. Read the exam from start to finish and allocate your time wisely. That is, do not spend a lot of time trying to answer a question that is only worth a few points. If you think any question is ambiguous, make and state a reasonable assumption. Answer all questions on this exam paper. Please make sure your writing and diagrams are legible. 1 of 1
1. (7 points) Describe the difference between a normal test-and-set spinlock and a read-before-test-and-set spin-lock. Why would the latter be advantageous over the former on multiprocessor systems? 2. (8 points) Describe the four conditions required for deadlock to occur. Describe a common method for deadlock prevention that prevents one of the conditions occurring. 2 of 2
3. (15 points) Here are two processes. Can they deadlock? If so, give a concurrent execution (show a combined sequence of the lettered steps of process0 [A,B,C,D,E,F,G,H] and the numbered steps of process1 [1,2,3,4,5,6,7,8] in which they deadlock and propose a change to one or both to make them deadlock free. lock *file1, *file2, *mutex; void process0() { lock_acquire(mutex); //Step A /* do something */ lock_acquire(file1); //Step B /* write to file 1 */ lock_acquire(file2); //Step C /* write to file 2 */ lock_release(file1); //Step D lock_release(mutex); //Step E /* do something */ lock_acquire(file1); //Step F /* read from file 1 */ /* write to file 2 */ lock_release(file2); //Step G lock_release(file1); //Step H void process1() { /* do stuff */ lock_acquire(file1); //Step 1 /* read from file 1 */ lock_acquire(file2); //Step 2 /* write to file 2 */ lock_release(file1); //Step 3 lock_release(file2); //Step 4 lock_acquire(mutex); //Step 5 /* do something */ lock_acquire(file1); //Step 6 /* write to file 1 */ lock_release(file1); //Step 7 lock_release(mutex); //Step 8 3 of 3
4. (8 points) A system has four page frames. The time of loading, time of last access, and the reference and modify bits for each page are as shown below (the times are in clock ticks, assume clock time 0 is when the machine was reset): Page Loaded Last referenced Reference bit Modify bit 0 126 280 1 0 1 230 265 0 1 2 140 270 0 0 3 110 285 1 1 a. Which page will the FIFO algorithm replace? Why? b. Which page will the LRU algorithm replace? Why? c. Under what circumstance do page faults occur? Describe the actions taken by the operating system when a page fault occurs. 5. (7 points) Consider a paged logical virtual address space (composed of 32 pages of 2Kbytes each) mapped into a 1 MByte physical memory space. a. What is the format of the processor s logical address? How many bits of the virtual address are used for the virtual page number AND how many are bits for the page offset? b. What is size (in total bytes) of the page table assuming each page table entry requires 4 bytes? 4 of 4
6. (15 points) For each of the following resource allocation graphs, find out whether there is a deadlock? 5 of 5
Given the following resource allocation diagram, a. If another instance of resource r1 is made available, is the deadlock resolved? If yes specify the allocation sequence, if no explain why? b. Repeat part a. for resource r2. c. Repeat part a. for resource r3. 6 of 6
7. (15 points) Consider the following two systems. Given that all resource instances are of the same type and using the definitions presented in the discussion of the Banker s Algorithm, answer these questions for each system: a. Determine the values in the Need matrix for each process in the system. b. Determine whether each of the systems is safe or unsafe. c. If the system is in a safe state, list a sequence of requests and releases that will make it possible for all processes to run to completion. d. If the system is in an unsafe state, show how it is possible for deadlock to occur. System 1 has 12 instances of the resource. Only 1 is available. Process Allocation Max 1 5 6 2 4 7 3 2 6 4 0 2 System 2 has 14 instances of the resource. 2 are available. Process Allocation Max 1 5 8 2 3 9 3 4 8 7 of 7
8. (15 points) Given the following information: Process number Arrival time Burst time 1 0 8 2 1 4 3 2 3 4 3 2 5 4 4 a) Draw a Gantt chart (time-line) for each of the following scheduling algorithms. First-come first-served Shortest job first Round robin (using a time quantum of 4) b) For the round robin algorithm above, compute the waiting time and turnaround time for each process (not the average). 8 of 8
9. (10 points) The following three interacting processes share two semaphores initialized as follows: Semaphore S1 = 3; Semaphore S2 = 0; P 1 : while (true) { wait (S1); print ( C ); signal (S2); P 2 : while (true) { wait (S2); print ( A ); print ( B ); signal (S2); P 3 : while (true) { wait (S2); print ( D ); a. Assuming execution is eventually halted, how many C s are printed when the set of processes runs? Explain your answer. b. What is the smallest number of A s that might be printed when this set of processes runs? Explain your answer. c. Is CCABBABDDCABD a possible output sequence when this set of processes runs? Explain your answer. 9 of 9