TheHingineer

  • Operating System


  • OS Part-1

  • OS Part-2

  • OS Part-3

  • OS Part-4

  • OS Part-5

  • Scheduling Algorithms in Operating System

    Introduction

    Scheduling algorithm decide karta hai ki kaunsa process CPU ko kab milega. Iska goal hota hai CPU utilization badhana, response time kam karna, aur processes ko fair execution dena.

    Types of Scheduling Algorithms

    Scheduling algorithms do tarah ke hote hain:

    1. -> Non-Preemptive Scheduling – Ek baar CPU kisi process ko mil gaya toh usko complete hone tak interrupt nahi kar sakte.

    2. -> Preemptive Scheduling – Running process ko beech me rok kar dusre process ko CPU diya ja sakta hai.


    1. First Come First Serve (FCFS) Scheduling

    • Type: Non-Preemptive

    • Working: Jo process pehle aayega, use CPU pehle milega.

    Example:

    ProcessArrival TimeBurst Time
    P105
    P213
    P328

    Gantt Chart

    | P1 | P2 | P3 |
    0    5    8    16
    • Turnaround Time (TAT) = Completion Time – Arrival Time

    • Waiting Time (WT) = Turnaround Time – Burst Time

    • (Burst Time: ek process ko CPU pr continuously chalne ke liye jitna actual time chahiye hota hai)

    ✅ Advantages: Simple aur easy to implement.
    ❌ Disadvantages: “Convoy Effect” hota hai (bade processes, chhoti processes ko delay kar dete hain).


    2. Shortest Job First (SJF) Scheduling

    • Type: Preemptive ya Non-Preemptive dono ho sakta hai.

    • Working: Jo process ka burst time sabse chhota hoga, usko pehle execute karenge.

    Example (Non-Preemptive)

    ProcessArrival TimeBurst Time
    P107
    P215
    P321
    P432

    Gantt Chart

    | P3 | P4 | P2 | P1 |
    2    4    9    16
     

    ✅ Advantages: Average waiting time kam hoti hai.
    ❌ Disadvantages: Longer processes starvation face kar sakte hain.


    3. Shortest Remaining Time First (SRTF)

    • Type: Preemptive version of SJF.

    • Working: Har time unit pe, jo process ka remaining burst time sabse kam hoga, usko CPU milega.

    ✅ Advantages: Turnaround time improve hota hai.
    ❌ Disadvantages: Frequent context switching ki wajah se overhead badhta hai.


    4. Priority Scheduling

    • Type: Preemptive ya Non-Preemptive dono ho sakta hai.

    • Working: Har process ki ek priority hoti hai, jiska priority high hoga, usko CPU milega.

    ProcessArrival TimeBurst TimePriority
    P1042
    P2131
    P3213

    Gantt Chart

    | P2 | P1 | P3 |
    1    4    5    6
     

    ✅ Advantages: Real-time systems ke liye useful.
    ❌ Disadvantages: Lower priority wale processes starvation face kar sakte hain.


    5. Round Robin (RR) Scheduling

    • Type: Preemptive

    • Working: Har process ko ek fixed time quantum milta hai. Agar process complete nahi hota, toh usko queue ke end me daal diya jata hai.

    Example (Time Quantum = 2)

    ProcessArrival TimeBurst Time
    P105
    P213
    P328

    Gantt Chart

    | P1 | P2 | P3 | P1 | P3 | P3 |
    0    2    4    6    8    10   12
     

    ✅ Advantages: Fair execution.
    ❌ Disadvantages: Frequent context switching se overhead badh jata hai.


    6. Multilevel Queue Scheduling

    • Type: Preemptive ya Non-Preemptive dono ho sakta hai.

    • Working: Processes ko different queues me divide kiya jata hai (jaise ki foreground, background). Har queue ka apna scheduling algorithm hota hai.

    ✅ Advantages: System aur user processes ko alag treat kar sakte hain.
    ❌ Disadvantages: Queue priorities manage karna difficult hota hai.


    Comparison of Scheduling Algorithms

    AlgorithmPreemptiveNon-PreemptiveBest For
    FCFSNoYesSimple workloads
    SJFNoYesBatch systems
    SRTFYesNoFast turnaround
    PriorityYes/NoYes/NoReal-time systems
    Round RobinYesNoTime-sharing OS
    Multilevel QueueYes/NoYes/NoMulti-user environments

    Conclusion

    Har scheduling algorithm ka apna advantage aur disadvantage hota hai. Round Robin multitasking ke liye best hai, jabki SJF aur Priority Scheduling fast turnaround provide karte hain. Kis algorithm ko use karna hai, yeh system ki requirement pe depend karta hai.

    Scroll to Top