1. Interrupt: communication between the device and the CPU. Typical examples are service requests and task completion reminders. For example, we are familiar with clock interruption and hard disk read/write service request interruption. The interruption is not related to whether the system is in the user or kernel state. It is only determined by a flag of the eflags register. We are familiar with STI. CLI commands are used to set this flag and decide whether to allow interruption. In a single CPU system, this is also a simple method to protect critical zones. The interrupt is asynchronous, because logically, the interrupt generation is irrelevant to the currently running process. In fact, interruption is so useful. Linux uses it to count the clock and read and write hard disks.
Interruption is generally divided into two categories: Synchronous interruption and asynchronous interruption. Synchronous interruption refers to the interruption caused by the CPU control unit during command execution. It is called "synchronous interruption" because the CPU sends such interruption signals only after a command is aborted. Asynchronous interruption (usually from the outside) refers to the interruption signal randomly generated by other hardware devices according to the CPU clock. In Intel 80x86 CPU manual, synchronous and asynchronous interrupts are also called "exception" and "interrupt" respectively )".
PS: it can be understood that interrupt in the narrow sense is actually an asynchronous interrupt, while interrupt in the broad sense also includes exception (Exceptions include fault and trap)
2. Programmable Interrupt (Programmable Interrupt): This type of interrupt can be triggered by the programmer using the int command. In Linux, the only programmable interrupt is the int 0x80 system call. The hardware processes programmable interruptions in a similar way to trap, that is, the next command from the returned exceptions to the triggered exceptions is returned. There is another saying about programmable interrupt: software interrupt.
Soft Interrupt uses the concept of hardware interrupt to simulate software to achieve macro asynchronous execution. In many cases, the soft interrupt is similar to the "signal". At the same time, the soft interrupt is opposite to the hard interrupt. "The Hard interrupt is the interrupt of the external device to the CPU ", "Soft Interrupt is usually the interrupt of the hard interrupt service program to the kernel", "the signal is from the kernel (or other processes) interruption to a process "(chapter 3 of Linux kernel source code scenario analysis ).
PS: in network programming, soft interruptions are used to trigger execution of protocol-layer code.
3. Fault and trap ):
Both of them are exceptions. Exceptions are generated by the processes currently being executed.
The most important difference between fault and trap is the difference in the EIP value they save when an error occurs. The error (fault) saves the EIP pointing to the command that triggered the exception; and the trap saves the EIP pointing to the next command that triggered the exception. Therefore, when an exception is returned, the error (fault) will re-execute the command, and the trap will not re-execute. This is actually quite important. For example, we are familiar with page faults. Because it is a fault, after the page missing exception is handled, it will also try to re-execute the command that triggers the exception (in most cases, the page is no longer missing ). The most important application is in debugging. When a debugged process encounters a breakpoint you set, it will stop waiting for your processing and wait until you re-execute it, of course, it will not execute breakpoint commands that have already been executed.