问题
How can kernel run all the time, when CPU can execute only one process at a time ? That is, if kernel is occupying CPU all the time , then how come other processes run.
Please explain Thank You
回答1:
In the same way that you can run multiple userspace processes at the same time: Only one of them is actually using the CPU at any given time. You have some interrupts that force them to give it up.
Code that is part of the operating system is no different here (except that it is in control of setting up this scheduling in the first place).
You also have to distinguish between processes run by the OS in the background (I suppose that is what you are talking about here), and system calls (which are being run as part of "normal" processes that temporarily switch into supervisor mode).
来源:https://stackoverflow.com/questions/33006604/how-can-kernel-run-all-the-time