PS

Priority Scheduling

Definition: Priority Scheduling assigns the CPU to the process with the highest priority (lowest numerical value, if lower number means higher priority). It can be preemptive or non-preemptive based on the system’s configuration.

Key Features:

  • Type: Can be Preemptive or Non-preemptive
  • Execution Rule: CPU is allocated to the process with the highest priority.
  • Tie-Breaker: FCFS is used if two processes have the same priority.
  • Drawback: May lead to starvation for lower-priority processes.
  • Solution to Starvation: Aging, which increases priority the longer a process waits.

Gantt Chart Example (Non-Preemptive Priority)

Given:

ProcessArrival TimeBurst TimePriority
P10103
P2211
P3324
P4412

Execution Trace

(Lower number = higher priority)

  • t=0 → P1 runs (no other processes yet)
  • t=10 → P2 runs (priority 1)
  • t=11 → P4 runs (priority 2)
  • t=12 → P3 runs (priority 4)

Gantt Chart

  gantt
    title Priority Scheduling (Non-Preemptive)
    dateFormat X
    axisFormat %s

    section Process Execution
    P1 (10)   :p1, 0, 10
    P2 (1)    :p2, 10, 11
    P4 (1)    :p4, 11, 12
    P3 (2)    :p3, 12, 14

Calculations

ProcessArrival TimeBurst TimeCompletion TimeTurnaround TimeWaiting Time
P10101010 - 0 = 100
P2211111 - 2 = 98
P3321414 - 3 = 119
P4411212 - 4 = 87

Averages

  • Average Waiting Time = (0 + 8 + 9 + 7) / 4 = 6.0
  • Average Turnaround Time = (10 + 9 + 11 + 8) / 4 = 9.5
Last updated on