[Operating system] Interrupts and system calls

The role of interrupts

There are two types of programs executed on the CPU: kernel programs and application programs

Under appropriate circumstances, the operating system kernel will actively give up the CPU usage rights to the application. "Interrupt" is the only way for the operating system kernel to regain the CPU usage rights (user mode to kernel mode).

Interrupt technology ensures concurrency.

Type of interrupt

Internal interrupt (exception) : related to the currently executed instruction, the interrupt signal comes from inside the CPU.

External interrupt : It has nothing to do with the currently executed instruction. The interrupt signal comes from outside the CPU.

example:

Interrupted within:

A trapped instruction can trigger an internal interrupt signal , and the program actively returns CPU control to the operating system kernel. "System calls" are completed by trapping instructions.

External interrupt:

Clock interrupt - an interrupt signal sent by the clock component to control concurrency.

I/O interrupt - an interrupt signal sent by an input and output device to tell the CPU that the task is completed.

Basic principles of the interrupt mechanism

        Different interrupt signals require different interrupt handlers to handle them . When the CPU detects an interrupt signal, it will query the " interrupt vector table " according to the type of the interrupt signal to find the storage location of the corresponding interrupt handler in the memory.

What is a system call

The operating system provides some simple services upwards, mainly including command interfaces and program structures. The program interface consists of a set of system calls.

Some library functions require the use of system calls.

System calls are classified by function: device management, file management, process management, process communication, and memory management. All operations related to shared resources must ensure the stability and security of the system.

System call process

High-level language code compiles machine language instructions, and the application program runs in user mode; the kernel program that handles system calls runs in core mode.

Pass the system call parameters -> execute the trapped instruction (user mode) -> execute the corresponding internal request kernel program to process the system call (core mode) -> return to the application.

The trapped instruction is executed in user mode . After executing the trapped instruction, an internal interrupt is triggered immediately , causing the CPU to enter the core state.

The system call request is issued in the user mode , and the corresponding processing of the system call is performed in the core mode.

Guess you like

Origin blog.csdn.net/l203018/article/details/132541569