[operating system] what are interrupts, exceptions, and system calls

Time:2021-12-3

 

***
 
 
abnormal
system call
source
Caused by peripherals,
It is random and sudden
Unexpected behavior of the application,
Is predictable
The application actively requests the operating system to provide services
Response mode
asynchronous
synchronization
Asynchronous / synchronous
Processing mechanism
Continuous and transparent to applications
Kill or re execute unexpected application instructions
Wait or continue
 
Interrupt (hard interrupt)
  • Meaning: the processing request initiated by the hardware device is called interrupt, such as I / O interrupt, clock interrupt (such as time slice), console interrupt, etc. Interrupt will also change the CPU from user state to kernel state, so that the operating system kernel can regain control of the CPU (which is also the only way for the kernel to regain CPU use right). Of course, the operating system kernel will actively give the CPU use right to the application program at the appropriate time.
  • handle:
    • Hardware processing: set the interrupt flag according to internal or external events, and then call the corresponding interrupt service routine according to the interrupt vector.
    • Software processing: first save on site, then perform interrupt service processing, and finally clear the interrupt flag and restore the site. (pause the operation of the application, save the operation state of the application, such as register data, and restore the application state after the interrupt processing is completed, that is, the interrupt service routine is completed)
 
Exception (soft interrupt)
  • Meaning: an application program executes an illegal instruction or a processing request that fails to execute the current instruction due to other reasons (such as CPU exception and memory error), which is called an exception.
  • Processing: the operating system kernel chooses to directly kill the process or prepare resources to retry the execution of application instructions (retry the failed instructions, which is transparent to the application).
 
System call (trapped)
  • Meaning: an application “actively” sends a service request to the operating system to call some simple and easy-to-use services provided by the system. Example: device management, file management, process control, process communication, memory management, etc
  • Processing: waiting or continuing. The shared resources of the system are uniformly managed by the kernel, so the calls to the shared resources must be coordinated and processed by the operating system kernel to ensure the stability and security of the system.