PRACTICE SET
CPU Scheduling Practice Sample
Process scheduling
Time: 15 minutesTotal Marks: 14
Note: Processes A, B and C arrive at time 0, in that order. They need 4, 2 and 3 milliseconds of CPU time. Assume one CPU and no switching overhead.
Scheduling exercise
1.Compare first-come, first-served with shortest-job-first scheduling. 2 x 3 = 6| Q.No | Questions | Marks |
|---|
| (a) | Under first-come, first-served, when does each process finish? | 2 | | Answer A finishes at 4 ms, B at 6 ms and C at 9 ms. | | (b) | Calculate the average waiting time under first-come, first-served. | 2 | | Answer A waits 0 ms, B waits 4 ms and C waits 6 ms. The average is (0 + 4 + 6) / 3 = 3.33 ms. | | (c) | Using non-preemptive shortest-job-first, give the execution order and average waiting time. | 2 | | Answer The order is B, C, A. Their waiting times are 0, 2 and 5 ms. The average is 7 / 3 = 2.33 ms. |
Interpreting a schedule
2.Use the same processes and arrival times. Show the time intervals in your working. 2 x 4 = 8| Q.No | Questions | Marks |
|---|
| (a) | A student says the last process always waits nine milliseconds because the CPU is busy for nine milliseconds. Use process C in the first schedule to explain the error. | 2 | | Answer Waiting time counts only the time a ready process spends waiting for the CPU. Under first-come, first-served, process C waits while A and B run, from time zero to time six. From time six to time nine C is running, so those final three milliseconds count toward its turnaround time but do not increase its waiting time. Its waiting time is six milliseconds and its turnaround time is nine milliseconds. | | (b) | If the scheduler switches from first-come, first-served to shortest-job-first, does the CPU finish the whole workload earlier? Explain why a learner could still prefer the second schedule. | 2 | | Answer Both schedules finish at time nine. Changing the order does not change how much processing is required, and there are no idle intervals or switching costs in this example. The advantage is that shorter jobs can finish earlier. B finishes at time two instead of time six. A takes longer to finish, but the reductions for the shorter jobs lower the average waiting time across the group. | | (c) | Now use round-robin scheduling with a two-millisecond time slice. Draw the timeline and calculate when process C first gets a response. | 2 | | Answer A runs from zero to two and has two milliseconds remaining. B runs from two to four and finishes. C runs from four to six and has one millisecond remaining. A then runs from six to eight and finishes. Finally C runs from eight to nine. Response time is the interval between arrival and the first opportunity to run. C arrives at zero and first runs at four, so its response time is four milliseconds. | | (d) | For that round-robin timeline, calculate the waiting time of A, B and C separately. Check your result using turnaround time minus CPU time. | 2 | | Answer A waits from time two to time six, giving four milliseconds. B waits from zero to two, giving two milliseconds. C waits from zero to four and again from six to eight, giving six milliseconds in total. The completion times are eight, four and nine. Subtracting the CPU times of four, two and three gives the same waiting times. This check also catches the common mistake of forgetting the second wait after a process loses its time slice. |
|