Course 4.2Lesson 2 of 3
An interrupt is a signal to the processor that something needs attention now. Hardware interrupts come from devices, such as a key press or a mouse movement. Software interrupts come from programs, such as a division by zero or two processes trying to use the same memory location.
Try the code and the simulations beside the lesson.
You are reading a book, and a friend taps your shoulder to ask a question. You mark your page, answer, and go back to reading. An interrupt works the same way. It is a signal sent to the processor to say that something needs its attention now.
Why not just let the processor look at each device again and again to see if it needs anything? It would waste a lot of time checking devices that have nothing to say. With interrupts, the processor gets on with its work, and each device or program signals when it needs something.
An interrupt is generated (made) when a device or a program needs the processor. The signal goes to the processor, which deals with it at the end of the instruction it is carrying out. There are two kinds, by where the signal comes from.
A hardware interrupt comes from a device. The syllabus gives two examples:
Other devices send hardware interrupts too. A printer can signal that it has run out of paper.
A software interrupt comes from a program, often because something has gone wrong. The syllabus gives two examples:
A process is a program while it is running.
Ask where the signal starts.
A key press is a hardware interrupt, even though a program then uses the key. The signal starts at the keyboard.
In the model below, each key press sends one interrupt. Even slow typing gives the processor many interrupts to handle.
The program stores four events with their kind, prints them and counts the hardware interrupts.
Try each one on your own first. If you are stuck, open a hint. Then check with Show the answer.
Every lesson is open to read. Enrolling also lets you:
Log in to join the discussion.
Loading…
This lesson is free to read. Enroll free to keep your place and take the tests.