OS function: handling interrupts

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

OS function: handling interrupts

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Which statement about interrupts is correct?
A The interrupted application program decides which ISR should deal with it
B The operating system receives the interrupt and decides which ISR should deal with it
2. A printer runs out of paper while a student is typing in a word processor. What does the OS do after the ISR finishes?
A It closes the word processor and restarts the computer
B It passes control back to the word processor so it can carry on
3. Two interrupts arrive at the same time: a key press and a power failure warning. Which does the OS handle first?
A The one with the higher priority, which is the power failure warning
B The one that arrived first in the alphabet, which is the key press
4. Which describes how the OS picks an ISR?
A It chooses the ISR that matches the type of interrupt, such as a keyboard or a divide by zero error
B It always runs the same ISR, whatever the interrupt is
5. Which statement is correct?
A Handling interrupts is one of the functions of an operating system
B Handling interrupts is only done by application software

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1OS interrupt handling AIF newInterrupt.priority > current.priority THEN run newInterrupt.ISR
2OS selects ISR BThe OS receives each interrupt, picks the right ISR to run, manages priorities, then passes control back to the interrupted program so it can carry on.
3The OS manages priorities: if a higher priority interrupt arrives, it is handled before a lower priority one. CThe application does not choose the ISR. The operating system receives the interrupt and selects the correct ISR.
4After the ISR has finished, the OS passes control back to the interrupted program so it carries on from where it stopped. DCALL ISR RESTORE state RESUME program
5After the ISR ends, the OS restarts the interrupted program from the very beginning. EWhen an interrupt arrives, the operating system chooses the correct interrupt service routine to deal with that particular interrupt, such as the keyboard ISR for a key press.
6The keyboard sends an interrupt and the application program picks the ISR to run. FThe OS does not restart the program. It restores the saved state and resumes the program from the point where it was interrupted.

Definitions

OS interrupt handling

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
IF interruptFlag = ____ THEN CALL OSHandler ENDIF
2.
IF source = "keyboard" THEN ____ keyboardISR ENDIF
3.
IF newPriority _ currentPriority THEN CALL higherISR ENDIF
4.
CALL keyboardISR ______ TO interruptedProgram
5.
REPEAT CALL nextISR _____ queueEmpty

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A Interrupt arrives at the OS
B OS finds the matching ISR
C OS runs the ISR
D OS deletes the paused program
Question 2
A WHILE program running
B IF no interrupt THEN
C OS selects the ISR
D ENDIF
E ENDWHILE
Question 3
A Keyboard priority = LOW
B Power failure priority = HIGH
C OS runs the LOW one first
D Then OS runs the LOW one
Question 4
A INPUT interrupt_type
B IF interrupt_type = KEYBOARD
C OS runs printer ISR
D ENDIF
Question 5
A Printer jams
B Printer sends interrupt to app
C OS runs the printer ISR
D OS shows an error message

Answer Key

OS function: handling interrupts
Section A: Quick Questions
Q1
B — The operating system receives the interrupt and decides which ISR should deal with it
Q2
B — It passes control back to the word processor so it can carry on
Q3
A — The one with the higher priority, which is the power failure warning
Q4
A — It chooses the ISR that matches the type of interrupt, such as a keyboard or a divide by zero error
Q5
A — Handling interrupts is one of the functions of an operating system
Section B: Match the Pairs
Q1
OS interrupt handling → The OS receives each interrupt, picks the right ISR to run, manages priorities, then passes control back to the interrupted program so it can carry on.
Q2
OS selects ISR → When an interrupt arrives, the operating system chooses the correct interrupt service routine to deal with that particular interrupt, such as the keyboard ISR for a key press.
Q3
The OS manages priorities: if a higher priority interrupt arrives, it is handled before a lower priority one. → IF newInterrupt.priority > current.priority THEN run newInterrupt.ISR
Q4
After the ISR has finished, the OS passes control back to the interrupted program so it carries on from where it stopped. → CALL ISR RESTORE state RESUME program
Q5
After the ISR ends, the OS restarts the interrupted program from the very beginning. → The OS does not restart the program. It restores the saved state and resumes the program from the point where it was interrupted.
Q6
The keyboard sends an interrupt and the application program picks the ISR to run. → The application does not choose the ISR. The operating system receives the interrupt and selects the correct ISR.
Section C: Definitions
Q1
OS interrupt handling — The OS receives each interrupt, picks the right ISR to run, manages priorities, then passes control back to the interrupted program so it can carry on.
Section D: Fill in the Blanks
Q1
IF interruptFlag = TRUE THEN CALL OSHandler ENDIF
Q2
IF source = "keyboard" THEN CALL keyboardISR ENDIF
Q3
IF newPriority > currentPriority THEN CALL higherISR ENDIF
Q4
CALL keyboardISR RETURN TO interruptedProgram
Q5
REPEAT CALL nextISR UNTIL queueEmpty
Section E: Spot the Error
Q1
D — After the ISR finishes, the OS must pass control back to the interrupted program so it can carry on. It should not delete it. The line should be: OS resumes the paused program.
Q2
B — The OS only selects an ISR when an interrupt has been received. The condition should be: IF interrupt received THEN.
Q3
C — The OS manages priorities, so the higher priority interrupt (power failure) is handled first. The line should be: OS runs the HIGH one first.
Q4
C — The OS must choose the ISR that matches the interrupt. A keyboard interrupt needs the keyboard ISR, not the printer ISR.
Q5
B — Interrupts are received by the operating system, not by an application. The line should be: Printer sends interrupt to OS.