Explain in detail what happens at both the hardware and software levels when an interrupt is triggered.