Course contentsShow
← Linux
Lesson 515 of 1,8195. Process Management and SignalingFree lesson

Interrupt Handling vs Process Execution

Discuss the priority of hardware interrupts compared to user-space process execution.

In this lesson, you will learn why hardware interrupts have the absolute "right of way" over any user-space process running on your CPU.

The Hierarchy of Execution

In Linux, your user-space applications—whether they are high-priority calculations or background daemons—are constantly being scheduled by the kernel. However, this scheduling is governed by a strict hierarchy. At the very top of this hierarchy sits the Hardware Interrupt.

When a peripheral device (like a network card or a keyboard) needs immediate attention, it sends an electrical signal to the CPU. The CPU is architecturally designed to pause whatever it is doing—even if it is in the middle of executing a user-space process—to handle that interrupt. This is known as "interrupt context."

Preemption by Hardware

Unlike the scheduler, which decides which process gets the next time slice, hardware interrupts do not "ask" to be scheduled. They preempt the CPU instantly. If you are running a heavy computational loop, the CPU state is saved, the current process is suspended, and the kernel enters the Interrupt Service Routine (ISR) to deal with the hardware event.

Consider this conceptual flow:

// Conceptual flow of a CPU core
while (running_process) {
    if (hardware_interrupt_received) {
        // CPU forces a pause here
        execute_interrupt_handler(); 
        // Once done, the CPU returns to the process
    }
    continue_process_execution();
}

Why Interrupts Win

Why does the kernel prioritize these signals? If a disk controller signals that data has arrived, that data must be moved from the buffer before it is overwritten. If a network packet arrives, it must be acknowledged promptly to prevent data loss. Because hardware doesn't have "memory" or wait-queues in the same way a process does, the CPU must react in real-time.

While your process might experience "jitter"—slight delays in execution—because of these frequent interrupts, it is a necessary trade-off for system stability. The CPU effectively acts as a servant to both the scheduler (for your code) and the hardware (for system integrity), but the hardware always gets the first word.

Key Takeaway: Hardware interrupts operate at a higher priority than user-space processes, allowing them to preempt the CPU instantly to ensure system hardware remains synchronized and responsive.