Upcoming SlideShare
×

# Final Exam OS fall 2012-2013 with answers

26,637 views

Published on

Final Exam for Operating systems part one _Fall_2012-2013-OS With answers

Published in: Education
1 Comment
11 Likes
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
• Thank you very much

Are you sure you want to  Yes  No
Views
Total views
26,637
On SlideShare
0
From Embeds
0
Number of Embeds
17
Actions
Shares
0
1,468
1
Likes
11
Embeds 0
No embeds

No notes for slide

### Final Exam OS fall 2012-2013 with answers

2. 2. Cairo University Faculty of Computers and Information Final ExamQuestion3: [16 marks]Consider the following set of processes, with the estimated CPU burst given in milliseconds, and lowerpriority numbers corresponding to higher CPU priority (1 is the highest): BurstThe processes are assumed, to have arrived in the order P1, P2, P3, P4, Process Priority TimeP5, all at time 0. P1 10 3 P2 1 1a. Draw four Gantt charts that illustrate the execution of these processes using the following scheduling algorithms: non-preemptive SJF, non- P3 2 3 preemptive priority (a smaller priority number implies a higher P4 1 4 priority), RR (quantum= 1), and RR (quantum= 2). P5 5 2 [6 marks] For the following two sections you must use the following table. Do not risk losing marks: N-P SJF N-P Priority turnaround time turnaround time RR(q=1) RR(q=2) turnaround Waiting turnaround Waiting turnaround Waiting turnaround WaitingP1P2P3P4P5b. Calculate the turnaround time of each process for each of the scheduling algorithms in part (a). [4 marks]c. Calculate waiting time of each process for each of these scheduling algorithms in part (a). [6 marks]SolutionChapter 5: CPU Schedulinga. Gantt chartsSJF P2 P4 P3 P5 P1 0 1 2 4 9 19non-preemptive priority P2 P5 P1 P3 P4 0 1 6 16 18 19RR(Q=1) P1 P2 P3 P4 P5 P1 P3 P5 P1 P5 P1 P5 P1 P5 P1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 19RR(Q=2) P1 P2 P3 P4 P5 P1 P5 P1 P5 P10 2 3 5 6 8 10 12 14 15 19 Page 2 of 6
3. 3. Cairo University Faculty of Computers and Information Final Exam N-P SJF N-P Priority turnaround time turnaround time RR(q=1) RR(q=2) turnaround Waiting turnaround Waiting turnaround Waiting turnaround WaitingP1 19 9 16 6 19 9 19 9P2 1 0 1 0 2 1 3 2P3 4 2 18 16 7 5 5 3P4 2 1 19 18 4 3 6 5P5 9 4 6 1 14 9 15 10b. Turnaround times turnaround turnaround turnaround turnaround time time time time SJF NP Priority RR(q=1) RR(q=2) P1 19 16 19 19 P2 1 1 2 3 P3 4 18 7 5 P4 2 19 4 6 P5 9 6 14 15c. Waiting times turnaround turnaround turnaround turnaround time time time time SJF NP Priority RR(q=1) RR(q=2) P1 9 6 9 9 P2 0 0 1 2 P3 2 16 5 3 P4 1 18 3 5 P5 4 1 9 10d. Average waiting time for all algorithms SJF: 9+0+2+1+4=16 16/5 = 3.2ms NP Priority: 6+0+16+18+1=41 41/5 = 8.2ms RR(Q=1): (14-5)+(1-0)+(6-1)+(3-0)+(14-5) =9+1+5+3+9=16 27/5 = 5.4ms. RR(Q=2): (15-6)+(2-0)+(3-0)+(5-0)+(14-4) =9+2+3+5+10=29 29/5 = 5.8ms. SJF has the shortest average waiting time.Question4: [6 marks]Consider a variant of the round robin scheduling algorithm where the entries in the ready queue arepointers to PCBs.a. What would be the effect on turn-around time for a process that has two pointers pointing to its PCB in the ready queue? [2 marks]b. Assume only two levels of priorities (with value two for the highest priority); draw a circle to show how the CPU time of eight (8) units is divided among P1, P2, P3, P4 and P5 with priorities [1, 1, 2, 2, 2] respectively. [2 marks] Page 3 of 6
4. 4. Cairo University Faculty of Computers and Information Final Examc. How would you modify the basic RR algorithm to achieve the same effect without the use of duplicate pointers? [2 marks]SolutionChapter 5: CPU Schedulinga. A process that has two pointers in the ready queue pointing to its PCB; will have increased its priority. It gets double the time quantum in a single cycle of round robin algorithm.b. Any process with priority 2 gets two pointers in the ready queue pointing at its PCB while a process with lower priority gets only one slice. P1 P3 P2 P4 P5c. Allow a process to get double the time quantum according to its priority.Question5: [6 marks]a. Assume two operations A(counter++) and B (counter--): [4 marks] A: register1 = Counter B: register2 = Counter; register1 = register1 + 1 register2 = register2 - 1 Counter = register1 Counter = register2 Show a computation sequence to illustrate how race condition may happen.b. Why must the semaphore methods Wait() and Signal() be atomic operations? [2 marks]Solution:Chapter 6: Process Synchronizationa. S0: producer execute register1 = Counter {register1 = 5} S1: producer execute register1 = register1 + 1 {register1 = 6} S2: consumer execute register2 = Counter {register2 = 5} S3: consumer execute register2 = register2 - 1 {register2 = 4} S4: producer execute counter = register1 { Counter = 6 } S5: consumer execute counter = register2 { Counter = 4}.b. The semaphore methods Wait() and Signal() be atomic operations in order to prevent race condition. Page 4 of 6
5. 5. Cairo University Faculty of Computers and Information Final ExamQuestion6: [6 marks]Consider the following code for solving Dinning philosophers’ problem. Write code, psedocode or a flowchart to describe what checks are needed as preconditions for changing state of Philosopher [i] to“eating” state.monitor DiningPhilosophers void putdown (int i) { {enum { THINKING; HUNGRY, EATING) state [5] ; state[i] = THINKING;condition self [5]; // test left and right neighborsvoid pickup (int i) test((i + 4) % 5);{ test((i + 1) % 5); state[i] = HUNGRY; } test(i); void test (int i) { /****missing code****/ }if (state[i] != EATING) self [i].wait; main() {} for (int i = 0; i < 5; i++) state[i] = THINKING; } }//End of MonitorSolution:Chapter 6: Process Synchronizationif ( (state[(i + 4) % 5] != EATING) && ………2 marks (state[i] == HUNGRY) && ………2 marks (state[(i + 1) % 5] != EATING) ) ………2 marks{ state[i] = EATING ; self[i].signal () ;} Page 5 of 6
6. 6. Cairo University Faculty of Computers and Information Final ExamQuestion7: [8 marks]Consider five processes P0 through P4; and three types of resources A (10 instances), B (5 instances),and C (7 instances). Consider the following snapshot of a system: Allocation Need Available ABC ABC ABC P0 010 743 230 P1 302 020 P2 302 600 P3 211 011 P4 002 431Use the safety algorithm to check if this system is in a safe state and specify the safe execution sequencethat you discovered (if any).Solution:Chapter 7: Deadlocks Allocation Need Available ABC ABC ABC P1 302 020 230 P3 211 011 532 P4 002 431 743 P0 010 743 745 P2 302 600 755 10 5 7Either of P1, P3, can start: <P1, P3, P4, P0, P2>Question8: [8 marks]Consider a logical address space of 32 pages of 2048 words each, mapped onto a physical memory of 8frames.a. How many bits are needed for addressing the total logical address? [2 marks]b. How many bits are needed to indicate the page number? [2 marks]c. How many bits are needed for addressing the physical address? [2 marks]d. What is the effect of allowing more than one entry in a page table (each entry belongs to a process) to point to the same frame in physical memory? [2 marks]Solution:Chapter 8: Main Memorya. 32*2048=25*211 =216Therefore 16 bits are needed for the logical address.b. 32 =25Therefore 5 bits are needed for the logical address.c. 8*2048=23*211 =214Therefore 14 bits are needed for the physical address.d. By allowing two entries in a page table to point to the same frame in memory, processes can share code and data. End of Exam Page 6 of 6