Reputation: 1843
In my lecture slides it says that an interrupt gets the attention of the CPU, but when I am reading online articles it says that interrupts get the attention of the OS. Can someone explain to me why there is a difference in text? Does the interrupt go to the OS first and then the OS contacts the CPU? I am quite confused here because initially I thought interrupts directly get the attention of the CPU, but it seems that it gets the attention of the OS first?
Upvotes: 0
Views: 114
Reputation: 223003
This post is about x86 only. Interrupts may work differently in other architectures.
There are two kinds of interrupts: hardware interrupts and software interrupts. Hardware interrupts are generated by hardware on your system: for example, the timer, devices (e.g., keyboard input), etc. Software interrupts are generated by code via the int
instruction.
In both cases, your operating system kernel has to install interrupt handlers that get called when an interrupt is triggered. An interrupt handler for the timer might cause the kernel to task-switch. A software interrupt would usually be for making system calls, as an entry point for user-level code to request functionality from the kernel (e.g., to open a file or read from a file descriptor); interrupts 0x21 (for DOS) and 0x80 (for Unix) are examples of system-call software interrupts.
To answer the question, a hardware interrupt would get the attention of the CPU, so to speak, but ultimately the OS kernel has to know what to do with it too, by installing a useful interrupt handler.
Upvotes: 1