Rather than the CPU main program constantly polling other programs to see if jobs are finished, other programs tell the CPU what's up by sending an interrupt anytime something significant happens (I.e. job finishes, receives important data from user, has an error, etc.). This saves time and let's CPU main program complete other functions.
Imagine a CPU that's OS implements Serial/ Sequential Processing as follows.
1. Fetch Instruction
2. Decode Instruction
3. Execute Instruction
4. Repeat with next process instruction
An interrupt It stops this, altering CPU job execution and tells the processor to stop what it's doing and do something else instead (current job stopped and temporarily replaced with another one)
Interrupts are given a priority based on importance, so OS know whether or not to stop an interrupt for a new different interrupt.
Jobs are stored in order of priority. When a processor is interrupted (or done executing a job), it will check its priority list. It will do whatever job is at the top of the list (could be current job or new job). If it is a new job, the OS will store the previous job in a register to save the work that's already been done. If there are multiple interrupted, unfinished jobs, they are stored in a stack within the register. Program ends after all jobs have been processed.
➢ Interrupt occurs → interrupt service routine → utilizes interrupt vector table → points to Interrupt Service Routines (ISRs).
➢ Interrupt saves the address of the interrupted instruction and the CPU acts accordingly.
➢ Trap or Exception → software-generated interrupt caused either by an error or a user request.
➢ An operating system is interrupt driven.
So, in order, when there is an interrupt.
1) CPU saves current context through a register, stack, program counter or other.
2) The CPU grabs the address of Interrupt Service Routine (ISR) from a vector table.
3) The CPU jumps to the Interrupt Handler
4) The ISR handles job, clearing flags, etc.
5) The Interrupt Handler exits
6) CPU restores context and returns to main flow
the main program doesn't even know what happens. It's business as normal.