SJF

Shortest Job First (SJF) Scheduling

Definition: SJF is a CPU scheduling algorithm where the process with the smallest CPU burst time is scheduled next.

Key Features:

  • Type: Can be Non-preemptive or Preemptive (Shortest Remaining Time First - SRTF)
  • Execution Rule: CPU is assigned to the process with the shortest next CPU burst.
  • Tie-Breaker: If two processes have the same burst time, FCFS is used.
  • Difficulty: Actual next CPU burst time is unknown, must be predicted (e.g., using exponential averaging).
  • Drawback: Potential for starvation of longer jobs.

Gantt Chart Example (Non-Preemptive SJF)

Given:

ProcessArrival TimeBurst Time
P106
P218
P327
P433

Execution Order (Non-Preemptive SJF)

At time 0 → only P1 is available → run P1 At time 6 → P2, P3, P4 are available → choose shortest: P4 At time 9 → P2, P3 are available → choose P3 At time 16 → run P2

Gantt Chart

  gantt
    title Non-Preemptive SJF Process Scheduling
    dateFormat X
    axisFormat %s

    section Process Execution
    P1 (6)    :p1, 0, 6
    P4 (3)    :p4, 6, 9
    P3 (7)    :p3, 9, 16
    P2 (8)    :p2, 16, 24

Calculations

ProcessArrival TimeBurst TimeStart TimeCompletion TimeWaiting TimeTurnaround Time
P1060606
P21816241523
P327916714
P4336936

Averages

  • Average Waiting Time = (0 + 15 + 7 + 3) / 4 = 6.25
  • Average Turnaround Time = (6 + 23 + 14 + 6) / 4 = 12.25
Last updated on