Comic: I went to eat at this wonderful restaurant last night and I was beaten out!

Note: This cartoon does not describe the actual working mode of the OS, and it is not so rigorous. It is much smaller than the real clock interruption that does not occur once every 200 milliseconds; for example, the operating system schedules processes instead Procedures, I hope these inaccurate places will not mislead you .

The main purpose of the comic is to illustrate the decisive role played by the clock interrupt in the process of program switching : the operating system is also a program, and when another program is running in the CPU, the operating system has no way to kick others out of the CPU and let itself To execute it, because the CPU will only execute in accordance with the instructions. If a certain program is executed all the time without transferring control to the operating system, the operating system will have no alternative.

Therefore, the operating system must cooperate with the CPU to complete the task switching. When the system starts, the operating system needs to set a clock and set the clock interrupt handler. When the system is running, let this clock give the CPU regularly Send a signal, when the CPU receives the clock interrupt, it will stop and find the clock interrupt handler to execute it. This interrupt handler will eventually call the scheduler set by the operating system. The scheduler will calculate how much time the process has taken. There is no need to switch, so that the concurrency of the process is realized.

More exciting technical comics, all in the programmers stand up

Guess you like

Origin blog.csdn.net/coderising/article/details/109348976