TheHingineer

  • Operating System


  • OS Part-1

  • OS Part-2

  • OS Part-3

  • OS Part-4

  • OS Part-5

  • Interrupt Service Routine (ISR) in Operating System

    1. Interrupt Kya Hota Hai?

    Interrupt ek signal hota hai jo hardware ya software CPU ko bhejta hai taaki uska dhyaan kisi important task par turant khicha ja sake. Jab interrupt aata hai, toh CPU apna current task temporarily pause karke ek special routine execute karta hai jise Interrupt Service Routine (ISR) kehte hain.

    Example:
    ✔ Jab aap keyboard par koi key press karte ho, toh ek interrupt generate hota hai jo OS ko batata hai ki koi input aaya hai.
    ✔ Jab printer ek page print kar leta hai, toh ek interrupt bhejta hai jo batata hai ki print complete ho gaya hai.


    2. Interrupt Service Routine (ISR) Kya Hai?

    Interrupt Service Routine (ISR) ek function hota hai jo interrupt aane par execute hota hai. Ye ensure karta hai ki jo bhi task zaroori hai, wo properly execute ho jaye aur phir CPU apna previous task resume kar sake.

    📌 Interrupt Handling Steps:

    1️⃣ Interrupt Generate Hota Hai – Ek hardware/software device interrupt signal bhejta hai.
    2️⃣ CPU Apna Current Task Pause Karta Hai – Jo kaam chal raha hai, usko temporarily roka jata hai.
    3️⃣ Interrupt Ka Source Identify Kiya Jata Hai – OS check karta hai ki kaunsa device ya software interrupt bhej raha hai.
    4️⃣ Interrupt Service Routine (ISR) Execute Hota Hai – Jo bhi zaroori operation hai, wo complete hota hai.
    5️⃣ CPU Apne Pehle Wale Task Par Wapas Jata Hai – ISR complete hone ke baad normal execution resume hota hai.

    🔹 Diagram: Interrupt Handling Process

    [User Task][Interrupt Occurs][Save Current State][Execute ISR][Resume Task]


    3. Types of Interrupts (Interrupt Ke Prakar)

    Operating System me do tareeke ke interrupts hote hain:

    1️⃣ Hardware Interrupts

    Ye hardware devices dwara generate kiye jate hain.

    🔹 Example:
    ✔ Jab aap keyboard par key press karte ho, ek interrupt CPU ko batata hai ki input aaya hai.
    ✔ Jab mouse move hota hai, ek interrupt OS ko notify karta hai.
    ✔ Jab printer ek page print kar leta hai, ek interrupt OS ko notify karta hai ki next page bhejo.

    2️⃣ Software Interrupts

    Ye software ya programs dwara generate kiye jate hain.

    🔹 Example:
    ✔ Agar ek program zero se divide karta hai (Divide-by-Zero Error), toh ek interrupt generate hota hai.
    ✔ Jab software OS se koi service request karta hai, toh ek interrupt generate hota hai.


    4. Device Driver aur ISR Kaise Kaam Karte Hain?

    • Device Drivers OS aur hardware ke beech communication enable karte hain.

    • Jab koi device attention maangta hai, toh wo ek interrupt CPU ko bhejta hai.

    • Interrupt Service Routine (ISR) jo device driver ke andar hoti hai, wo us interrupt ko handle karti hai aur zaroori kaam complete karti hai.

    📌 Example: Keyboard Interrupt Handling

    1️⃣ Aap keyboard par ek key press karte ho.
    2️⃣ Ek hardware interrupt CPU ko bhej diya jata hai.
    3️⃣ CPU temporarily apna kaam stop karta hai aur Keyboard ISR ko call karta hai.
    4️⃣ ISR keyboard buffer se data read karta hai.
    5️⃣ ISR ye data OS ko send karta hai, aur CPU apna previous task resume karta hai.

    🔹 Diagram: Keyboard Interrupt Handling

    [Key Pressed][Interrupt Signal Sent][ISR Reads Key][OS Receives Input][Task Resumes]


    5. Interrupt Priority Aur Handling Techniques

    🔹 Interrupt Priority Levels (Kaunsa Interrupt Pehle Process Hoga?)
    Har interrupt ka priority level alag hota hai.

    • High Priority – Power failure, system crash.

    • Medium Priority – Hard disk request, network request.

    • Low Priority – Keyboard input, mouse movement.

    🔹 Interrupt Handling Techniques

    1. Vectored Interrupts – Har interrupt ka apna alags ISR hota hai, jo CPU us interrupt ke liye direct execute karta hai.

    2. Polled Interrupts – CPU ek ek device check karta hai aur identify karta hai ki kaunsa device interrupt generate kar raha hai.


    6. Conclusion

    ✔ Interrupts CPU ko batate hain ki koi important event hua hai jo handle karna zaroori hai.
    ✔ Interrupt Service Routine (ISR) ensure karta hai ki interrupt sahi se process ho.
    ✔ ISRs device drivers ke andar hoti hain aur hardware interrupts ko manage karti hain.
    ✔ Interrupts ka priority level hota hai, taaki important interrupts pehle process ho sakein.

    Scroll to Top