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:

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

    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)

    Process Arrival Time Burst Time
    P1 0 7
    P2 1 5
    P3 2 1
    P4 3 2

    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.

    Process Arrival Time Burst Time Priority
    P1 0 4 2
    P2 1 3 1
    P3 2 1 3

    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)

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

    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

    Algorithm Preemptive Non-Preemptive Best For
    FCFS No Yes Simple workloads
    SJF No Yes Batch systems
    SRTF Yes No Fast turnaround
    Priority Yes/No Yes/No Real-time systems
    Round Robin Yes No Time-sharing OS
    Multilevel Queue Yes/No Yes/No Multi-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