We wish to schedule three processes P1, P2 and P3 on a uniprocessor system.…

2005

We wish to schedule three processes P1, P2 and P3 on a uniprocessor system. The priorities, CPU time requirements and arrival times of the processes are as shown below.

image.png

We have a choice of preemptive or non-preemptive scheduling. In preemptive scheduling, a late-arriving higher priority process can preempt a currently running process with lower priority. In non-preemptive scheduling, a late-arriving higher priority process must wait for the currently executing process to complete before it can be scheduled on the processor.

What are the turnaround times (time from arrival till completion) of P2 using preemptive and non-preemptive scheduling respectively.

  1. A.

    30 sec, 30 sec

  2. B.

    30 sec, 10 sec

  3. C.

    42 sec, 42 sec

  4. D.

    30 sec, 42 sec

Attempted by 119 students.

Show answer & explanation

Correct answer: D

Preemptive scheduling: timeline and calculation.

  • 00:00:00 to 00:00:03: P3 runs (3 sec), remaining 12 sec.

  • 00:00:03 to 00:00:05: P2 runs (2 sec), remaining 8 sec.

  • 00:00:05 to 00:00:25: P1 (highest priority) runs uninterrupted and finishes.

  • 00:00:25 to 00:00:33: Remaining 8 sec of the process that arrived at 00:00:03 runs and finishes at 00:00:33.

Turnaround for the process that arrived at 00:00:03 = completion 00:00:33 - arrival 00:00:03 = 30 sec.

Non-preemptive scheduling: timeline and calculation.

  • 00:00:00 to 00:00:15: P3 runs to completion (15 sec).

  • 00:00:15 to 00:00:35: P1 (higher priority among waiting) runs and finishes.

  • 00:00:35 to 00:00:45: The process that arrived at 00:00:03 runs (10 sec) and finishes at 00:00:45.

Turnaround for the process that arrived at 00:00:03 = completion 00:00:45 - arrival 00:00:03 = 42 sec.

Answer: Preemptive: 30 sec, Non-preemptive: 42 sec.

A video solution is available for this question — log in and enroll to watch it.

Explore the full course: Gate Guidance By Sanchit Sir