WikiGalaxy

Personalize

Shortest Job Next (SJN) Scheduling

Overview

Shortest Job Next (SJN), also known as Shortest Job First (SJF), is a scheduling algorithm that selects the process with the smallest execution time to run next. It is a non-preemptive scheduling algorithm, meaning once a process starts executing, it runs to completion.

Advantages

  • Minimizes average waiting time.
  • Efficient for batch processing systems.

Disadvantages

  • Can lead to starvation for longer processes.
  • Requires precise knowledge of execution times, which can be difficult to predict.

Use Cases

  • Suitable for batch processing where job lengths are known.
  • Not ideal for time-sharing systems.

Example 1: Basic SJN Scheduling

Scenario

Consider three processes P1, P2, and P3 with burst times of 6, 8, and 7 units respectively. The SJN algorithm selects the shortest job first.


Process    Burst Time
P1         6
P2         8
P3         7

Order of Execution: P1 -> P3 -> P2
        

Explanation

In this example, process P1 is executed first as it has the shortest burst time. After P1, P3 is chosen over P2 due to its shorter burst time.

Example 2: Handling Identical Burst Times

Scenario

Consider three processes P1, P2, and P3 with burst times of 5, 5, and 10 units respectively. The SJN algorithm must handle processes with identical burst times.


Process    Burst Time
P1         5
P2         5
P3         10

Order of Execution: P1 -> P2 -> P3
        

Explanation

When two processes have identical burst times, SJN may choose based on arrival order or priority, if specified. Here, P1 and P2 have identical burst times, so they are scheduled in their order of arrival.

Example 3: Starvation Issue

Scenario

Consider a system where new short processes keep arriving, causing longer processes to wait indefinitely.


Process    Burst Time
P1         20
P2         2
P3         2
P4         2

Order of Execution: P2 -> P3 -> P4 -> (New Short Process) -> P1
        

Explanation

The continuous arrival of short processes (P2, P3, P4) causes P1 to experience starvation. This is a significant drawback of the SJN algorithm.

Example 4: Preemptive Version (SRTF)

Scenario

The Shortest Remaining Time First (SRTF) is a preemptive extension of SJN, where the process with the shortest remaining time is selected for execution.


Process    Arrival Time    Burst Time
P1         0              8
P2         1              4
P3         2              9
P4         3              5

Order of Execution: P1 (0-1) -> P2 (1-5) -> P4 (5-10) -> P1 (10-14) -> P3 (14-23)
        

Explanation

SRTF allows preemption, so when P2 arrives at time 1, it preempts P1. This continues with the shortest remaining time being selected at each step.

Example 5: SJN in Batch Systems

Scenario

In a batch processing system, jobs are submitted with known execution times, allowing SJN to optimize job scheduling.


Job    Burst Time
J1     10
J2     5
J3     8
J4     6

Order of Execution: J2 -> J4 -> J3 -> J1
        

Explanation

SJN efficiently schedules jobs in a batch system by minimizing the average waiting time, as jobs are executed in the order of their burst times.

logo of wikigalaxy

Newsletter

Subscribe to our newsletter for weekly updates and promotions.

Privacy Policy

 • 

Terms of Service

Copyright © WikiGalaxy 2025