简体   繁体   中英

How does operating system invoke user-scheduled task that to execute when its time comes to?

I'm not sure how to phrase this question, but i'll try my best. When we schedule some abstract task in a real-time, how is it invoked on time (task can be anything that has been scheduled to happen at some point in time, like alarm that wakes you up in the morning)? What happens at the lowest level of software? For example in .NET WaitHandle.WaitOne(1000), how is it implemented? Is there some operating system scheduler (i'm not talking about time slicing between threads) that every software platform uses to schedule its task? When system clock goes one tick, does it say somehow to operating system "hey, one tick elapsed, increase your system time!". And then operating system increases its time and tells its scheduler to check if there are some events scheduled to occur at this new time? Or scheduler runs on separate thread in infinite loop, check system time in each iteration and see if it has something scheduled to invoke? Or there is no scheduler and each component runs infinite loops on its own? I assume that idea is the same on every operating system, but if its not, i'm interested specifically in what happens on Windows OS and .NET.

Kind regards,

The state of a process is defined by a set of registers called the process context. This set of registers includes the values of the general registers and system registers that are only accessible in kernel mode.

Most processors define a data structure called the Process Context Block (PCB). The PCB has a slot for each of the registers.

To make a context switch from one process to another, the operating system causes the registers of the current process to be saved in its PCB then loads the registers from the PCB of the new process.

Most processors have load process context and save process context instructions to this can be done all at once. A number of incompetently designed processors in widespread use can require multiple instructions to do these tasks.

There is something called Programmable Interval Timer. It can be programmed to count number of ticks and then send signal to os. The os will then wake up the process. To read more about PIT, refer to osdev

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM