L-2.4: Shortest Job First(SJF) Scheduling  Algorithm with  Example | Operating System

L-2.4: Shortest Job First(SJF) Scheduling Algorithm with Example | Operating System

Understanding Shortest Job First Scheduling Algorithm

Introduction to the Concept

  • The video introduces the Shortest Job First (SJF) scheduling algorithm, focusing on four processes: P1, P2, P3, and P4. It outlines the need to calculate completion time, turnaround time, waiting time, and response time for these processes.

Key Characteristics of SJF

  • The SJF algorithm prioritizes processes based on their burst time; shorter burst times are executed first.
  • This scheduling mode is non-preemptive, meaning once a process starts executing on the CPU, it runs to completion without interruption.

Gantt Chart Utilization

  • The explanation begins with a Gantt chart to visualize process execution over time. Time tracking starts from zero.
  • At time 0, no processes have arrived; thus, the CPU remains idle until at least one process arrives.

Arrival and Execution of Processes

  • At time 1, both P1 and P3 arrive. Burst times are compared to determine which process will execute first.
  • Since P3 has a shorter burst time (2 units), it is selected for execution first. Its total execution takes place from time 1 to 3.

Continuing Process Selection

  • After executing P3 completely by time 3, the next step involves checking which processes have arrived by that point—P1 and P2 are in consideration.
  • With both processes available in the ready queue (P1 with a burst of 3 and P2 with a burst of 4), selection criteria focus again on burst times.

Handling Equal Burst Times

  • When evaluating remaining processes at time 6 (P2 and newly arrived P4), both have equal burst times (4). Arrival times become crucial for decision-making.
  • Since P2 arrived before P4 at time 2 versus an assumed arrival of 4 for P4, it is selected next despite equal burst durations.

Final Execution Steps

  • After executing all prior processes up to their respective completion points (P1 at 6 and then running through others), only P4 remains. It executes last from time 10 to completion at 14.

Calculating Completion Times

  • Completion times are recorded as follows:
  • P1: Completed at 6
  • P2: Completed at 10
  • P3: Completed at 3
  • P4: Completed at 14

Turnaround Time & Waiting Time Calculation

  • Turnaround Time (TAT): TAT = Completion Time - Arrival Time:
  • For each process calculated accordingly leading to values like TAT for P1 being 5, etc.
  • Waiting Time (WT): WT = TAT - Burst Time:
  • Each waiting period derived similarly results in specific values such as WT for each process being calculated directly from previous results.

Understanding Response Time and Turnaround Time in Pre-emptive Scheduling

Key Concepts of Pre-emptive Scheduling

  • In pre-emptive scheduling, response time is not calculated as it equates to waiting time. If asked, one can explain the calculation method for clarity.
  • When a process receives CPU time in a pre-emptive system, it executes completely without interruption. This means that once a process gets CPU access, it will finish its execution before another process can take over.

Implications of CPU Switching

  • In pre-emptive cases, the CPU may switch between processes multiple times. This allows for fairness in resource allocation but complicates response time calculations.
  • Since response time equals waiting time in this context, it's acceptable to omit direct calculations for response time when discussing average turnaround times.

Average Turnaround Time Calculation

Video description

🚀 Enroll Now in GATE DA exam course 2025🌟 🔗To Enroll, Login to: https://www.gatesmashers.com/ 💰Course Price: 2999/- (Non-Refundable) 🕒Course starting Date: 5th March 2024 📞 Contact us: For any queries or assistance, feel free to reach us on WhatsApp or call at 8295451354. 🕒Validity of Course: 31st March, 2025 👉Subscribe to our new channel:https://www.youtube.com/@varunainashots Shortest Job First (SJF) is an algorithm in which the process having the smallest execution time is chosen for the next execution. This scheduling method can be preemptive or non-preemptive. It significantly reduces the average waiting time for other processes awaiting execution. ►Operating System (Complete Playlist): https://www.youtube.com/playlist?list=PLxCzCOWd7aiGz9donHRrE9I3Mwn6XdP8p Other subject-wise playlist Links: -------------------------------------------------------------------------------------------------------------------------------------- ►Design and Analysis of algorithms (DAA): https://www.youtube.com/playlist?list=PLxCzCOWd7aiHcmS4i14bI0VrMbZTUvlTa ►Database Management System: https://www.youtube.com/playlist?list=PLxCzCOWd7aiFAN6I8CuViBuCdJgiOkT2Y ► Theory of Computation https://www.youtube.com/playlist?list=PLxCzCOWd7aiFM9Lj5G9G_76adtyb4ef7i ►Artificial Intelligence: https://www.youtube.com/playlist?list=PLxCzCOWd7aiHGhOHV-nwb0HR5US5GFKFI ►Computer Networks (Complete Playlist): https://www.youtube.com/playlist?list=PLxCzCOWd7aiGFBD2-2joCpWOLUrDLvVV_ ►Computer Architecture (Complete Playlist): https://www.youtube.com/playlist?list=PLxCzCOWd7aiHMonh3G6QNKq53C6oNXGrX ►Structured Query Language (SQL): https://www.youtube.com/playlist?list=PLxCzCOWd7aiHqU4HKL7-SITyuSIcD93id ►Discrete Mathematics: https://www.youtube.com/playlist?list=PLxCzCOWd7aiH2wwES9vPWsEL6ipTaUSl3 ►Compiler Design: https://www.youtube.com/playlist?list=PLxCzCOWd7aiEKtKSIHYusizkESC42diyc ►Number System: https://www.youtube.com/playlist?list=PLxCzCOWd7aiFOet6KEEqDff1aXEGLdUzn ►Cloud Computing & BIG Data: https://www.youtube.com/playlist?list=PLxCzCOWd7aiHRHVUtR-O52MsrdUSrzuy4 ►Software Engineering: https://www.youtube.com/playlist?list=PLxCzCOWd7aiEed7SKZBnC6ypFDWYLRvB2 ►Data Structure: https://www.youtube.com/playlist?list=PLxCzCOWd7aiEwaANNt3OqJPVIxwp2ebiT ►Graph Theory: https://www.youtube.com/playlist?list=PLxCzCOWd7aiG0M5FqjyoqB20Edk0tyzVt ►Programming in C: https://www.youtube.com/playlist?list=PLxCzCOWd7aiGmiGl_DOuRMJYG8tOVuapB ►Digital Logic: https://www.youtube.com/playlist?list=PLxCzCOWd7aiGmXg4NoX6R31AsC5LeCPHe --------------------------------------------------------------------------------------------------------------------------------------- Our social media Links: ► Subscribe to us on YouTube: https://www.youtube.com/gatesmashers ►Subscribe to our new channel: https://www.youtube.com/@varunainashots ► Like our page on Facebook: https://www.facebook.com/gatesmashers ► Follow us on Instagram: https://www.instagram.com/gate.smashers ► Follow us on Instagram: https://www.instagram.com/varunainashots ► Follow us on Telegram: https://t.me/gatesmashersofficial ► Follow us on Threads: https://www.threads.net/@gate.smashers -------------------------------------------------------------------------------------------------------------------------------------- ►For Any Query, Suggestion or notes contribution: Email us at: gatesmashers2018@gmail.com