TheHingineer

  • Operating System


  • OS Part-1

  • OS Part-2

  • OS Part-3

  • OS Part-4

  • OS Part-5

  • Process Scheduling in OS – Preemptive & Non-Preemptive Scheduling 

    1. Process Scheduling Kya Hota Hai?

    👉 Process Scheduling ek technique hai jisme OS decide karta hai ki kaunsa process CPU pe chalega aur kitni der tak.
    👉 Kyunki CPU time limited hota hai, OS ensure karta hai ki sabhi processes efficiently execute ho sakein.

    Scheduling Criteria (Performance Parameters)

    Ek achha scheduling algorithm in factors ko optimize karta hai:

    🔹 CPU Utilization – CPU hamesha busy rahe.
    🔹 Throughput – Kitne processes ek second me complete ho rahe hain.
    🔹 Turnaround Time – Process submit hone se lekar complete hone tak ka total time.
    🔹 Waiting Time – Process CPU milne ka kitna wait karta hai.
    🔹 Response Time – Process request bhejne ke baad pehli baar response milne me kitna time lagta hai.


    2. Process Scheduling ke Types

    Process Scheduling CPU allocation aur interruption ke basis pe do types me divide hota hai:

    (A) Preemptive Scheduling

    👉 Isme ek process ko CPU se hata kar dusre process ko diya ja sakta hai.
    👉 Process execution ke beech me bhi interrupt ho sakta hai.
    👉 Multitasking aur real-time systems me use hota hai.

    Example of Preemptive Scheduling:

    🔹 Suppose teen processes P1, P2, P3 hain.
    🔹 P1 start hota hai, par thodi der baad P2 higher priority ka aata hai.
    🔹 CPU P1 se le kar P2 ko de diya jata hai (Preemption hoti hai).

    Diagram for Preemptive Scheduling:

    Time     4       8    10
          |P1| → |P2| → |P1| → |P3|

    🔹 P1 shuru hota hai (0 sec par)
    🔹 P2 higher priority ka aaya (2 sec par) aur P1 ko preempt kar diya
    🔹 P1 dobara execute hota hai P2 ke khatam hone ke baad
    🔹 P3 execute hota hai last me

    🔹 Common Preemptive Scheduling Algorithms:
    ✅ Round Robin (RR) – Har process ko ek fixed time (time quantum) milta hai.
    ✅ Shortest Remaining Time First (SRTF) – Sabse kam remaining time wale process ko CPU milta hai.
    ✅ Priority Preemptive Scheduling – Higher-priority process lower-priority wale ko preempt kar deta hai.


    (B) Non-Preemptive Scheduling

    👉 Ek baar process ko CPU mil gaya to jab tak wo complete na ho jaye, usko nahi hataya jata.
    👉 CPU process ke complete hone tak uske paas hi rehta hai.
    👉 Batch processing systems me use hota hai.

    Example of Non-Preemptive Scheduling:

    🔹 Suppose teen processes P1, P2, P3 hain.
    🔹 P1 start hota hai aur jab tak complete na ho, CPU usi ke paas rahta hai.
    🔹 Uske baad hi P2 execute hoga, phir P3.

    Diagram for Non-Preemptive Scheduling:

    Time0     5        10      15
           | P1 | → | P2 | → | P3 |

    🔹 P1 execute hota hai (0 se 5 sec tak)
    🔹 P2 execute hota hai (5 se 10 sec tak)
    🔹 P3 execute hota hai (10 se 15 sec tak)

    🔹 Common Non-Preemptive Scheduling Algorithms:
    ✅ First Come First Serve (FCFS) – Jo process pehle aata hai, usko CPU pehle milta hai.
    ✅ Shortest Job First (SJF) – Jiska execution time sabse kam hota hai, wo pehle execute hota hai.
    ✅ Priority Scheduling (Non-Preemptive) – Higher-priority process execute hota hai, lekin ek baar start hone ke baad usko interrupt nahi kiya jata.


    3. Preemptive vs Non-Preemptive Scheduling ka Difference

    Feature Preemptive Scheduling Non-Preemptive Scheduling
    Process Interruption Haan, process ko beech me interrupt kiya ja sakta hai Nahi, ek baar start ho gaya to complete hone tak chalega
    Response Time Fast, kyunki priority wale processes ko jaldi CPU milta hai Slow, kyunki process wait karta hai
    CPU Utilization High, kyunki CPU idle nahi rehta Low, kyunki kabhi-kabhi CPU idle ho sakta hai
    Overhead Jyada, kyunki frequent context switching hota hai Kam, kyunki koi context switching nahi hoti
    Example Algorithms Round Robin, SRTF, Priority (Preemptive) FCFS, SJF, Priority (Non-Preemptive)

    4. Summary (Short Notes)

    ✔ Process scheduling CPU execution ko manage karta hai.
    ✔ Preemptive scheduling me process interrupt ho sakta hai (e.g., Round Robin, SRTF).
    ✔ Non-preemptive scheduling me process complete hone tak chalega (e.g., FCFS, SJF).
    ✔ Preemptive scheduling multitasking aur real-time systems me use hota hai, jabki non-preemptive simple aur low-overhead hota hai

    Scroll to Top