Skip to main content

Preemptive priority scheduling (4, 10, 5 ms)

Short answer

Execution order P1, P3, P4, P3, P2 results in waiting times P1=0, P2=12, P3=7, P4=0 ms. Average waiting time = 4.75 ms, average turnaround time = 10.25 ms.

Three processes P1, P2 and P3 with estimated completion time 4, 10, 5 ms and priorities 1, 3, 2 respectively enter the ready queue together. A new process P4 with estimated completion time 3 ms and priority 0 enters the ready queue after 5 ms of start of operation. Calculate WT, TAT for each process and calculate AWT and ATAT using preemptive priority based scheduling algorithms.

In preemptive priority scheduling the CPU always runs the ready process with the highest priority; a newly arrived higher-priority process preempts the running one. Lower priority number means higher priority. Assumed: P1, P2, P3 arrive at 0; P4 arrives at 5 ms.

Gantt chart

| P1 | P3 | P4 | P3 | P2 |
0    4    5    8    12   22

Trace

  • 0-4: P1 (priority 1) is the highest among P1, P2, P3 and finishes at 4.
  • 4-5: P3 (priority 2) runs; P2 has priority 3.
  • 5: P4 (priority 0) arrives and preempts P3, which has 4 ms left.
  • 5-8: P4 runs to completion.
  • 8-12: P3 resumes and finishes.
  • 12-22: P2 runs last.

Calculation

TAT = completion time - arrival time; WT = TAT - burst time.

ProcessATBTCTTAT = CT - ATWT = TAT - BT
P104440
P2010222212
P30512127
P453830

AWT = (0 + 12 + 7 + 0) / 4 = 19/4 = 4.75 ms

ATAT = (4 + 22 + 12 + 3) / 4 = 41/4 = 10.25 ms

Answer: AWT = 4.75 ms, ATAT = 10.25 ms.

✓ Answer checked by Claude Opus 5.5 (high effort)

All Embedded System chapter 6 questions →