L-2.8: Pre-emptive Priority  Scheduling Algorithm with  Example | Operating System

L-2.8: Pre-emptive Priority Scheduling Algorithm with Example | Operating System

Understanding Priority Scheduling with Preemption

Introduction to Priority Scheduling

  • The video introduces the concept of priority scheduling in CPU management, focusing on preemptive modes. It presents a numerical example involving four processes with specified arrival and burst times.
  • The criteria for priority scheduling is explained: higher numbers indicate higher priorities, which can be confusing if not clearly stated.

Process Execution Steps

  • The speaker emphasizes the importance of identifying which process has arrived at time zero before executing any tasks.
  • If only one process arrives, it is executed immediately; however, if multiple processes arrive simultaneously, priority must be assessed.

Handling Multiple Processes

  • At time 1, both P1 and P2 are present. Since P2 has a higher priority (higher number), it preempts P1.
  • In preemptive mode, each process runs for only one time unit to avoid skipping over higher-priority processes.

Gantt Chart Execution

  • After running P1 for one time unit, the remaining burst time is reduced accordingly.
  • At time 2, all three processes (P1, P2, and now P3) are checked for their priorities again.

Continuing Process Management

  • As execution continues at each timestamp (e.g., from 3 to 4), the highest-priority process is always selected to run next.
  • When a new process arrives (P4 at time 4), its priority is evaluated against existing processes before deciding which to execute next.

Finalizing Execution Order

  • Once all processes have been executed based on their priorities and remaining burst times are accounted for correctly.
  • The final steps involve executing the remaining processes based on their priorities until completion times are established.

Conclusion of Scheduling Example

  • The video concludes by summarizing that once all processes have arrived and been prioritized correctly, they can be executed without further interruption as non-preemptive scheduling.

How to Calculate Turnaround Time and Waiting Time in Scheduling

Understanding Completion Time and Turnaround Time

  • The completion time (CT) for processes is calculated by noting the last written process times. For example, P2 has a CT of 8, P3 is 4, and P4 is 5.
  • The formula for calculating turnaround time (TAT) is: TAT = Completion Time - Arrival Time. This results in values such as 12, 7, 2, and 1.

Calculating Waiting Time

  • Waiting time (WT) can be derived from the formula: WT = Turnaround Time - Burst Time. It’s crucial to use the original burst times to avoid common mistakes.
  • Example calculations yield waiting times of:
  • For TAT of 12 with burst time of 5: WT = 12 - 5 = 7
  • For TAT of 7 with burst time of 4: WT = 7 - 4 = 3
  • For TAT of 2 with burst time of 4: WT = 2 - 4 = 0
  • For TAT of 1 with burst time of 1: WT = 1 -1 = 0

Average Waiting and Turnaround Times

  • To find average waiting or turnaround times, sum the individual times and divide by the number of processes.
  • Total turnaround time (TAT): 22, divided by number of processes (4), gives an average TAT of 5.5.
  • Total waiting time (WT): 10, divided by number of processes (4), results in an average WT of 2.5.

Priority Scheduling Insights

  • In priority scheduling with preemption, remember that you only run each process for up to one unit at a time.
  • When two or more processes have equal priority and arrive simultaneously, check their arrival times to determine which runs first.
Video description

👉Subscribe to our new channel:https://www.youtube.com/@varunainashots In pre-emptive priority scheduling algorithm, every time a process with higher priority arrives in the waiting queue, the CPU cycle is shifted to the process with the highest priority. This is pre-emptive because a process that's already being executed can be stopped to execute a process with higher priority. ►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