Interrupts and Buffers ⚡

Efficient computing relies on the Operating System's ability to multitask and manage the speed differences between the CPU and external devices.

Interrupts 🔔

An interrupt is a signal sent from a device or software to the CPU, requesting immediate attention.

Examples:

  • Keyboard key press ⌨️
  • Printer out of paper 🖨️
  • Software error (e.g., divide by zero) ❌
  • Timer interrupt ⏱️

Buffers 📦

A buffer is a temporary memory area used to hold data while it is being moved, compensating for speed differences between hardware.

Examples:

  • Streaming video (prevents stuttering) 🎥
  • Sending a document to a printer 📄
  • Hard drive data transfer 💾

6. How the OS Handles Interrupts 🛠️

When an interrupt occurs, the OS must ensure the current task is not lost. It follows these steps:

1. Completion The CPU finishes its current Fetch-Decode-Execute cycle.
2. Status Check The CPU checks for any pending interrupts before starting the next cycle.
3. Preservation The current state (contents of registers and Program Counter) is saved to the stack.
4. ISR Execution The OS identifies the source and loads the appropriate Interrupt Service Routine (ISR).
5. Restoration Once handled, the saved state is loaded back from the stack, and the original process resumes.
💡 Exam Tip: Remember, the main purpose of a Buffer is to allow the CPU to continue with other tasks while the slower hardware processes the data, whereas an Interrupt is all about getting the CPU to drop everything to handle an urgent request.