Answer the question
In order to leave comments, you need to log in
What does "time quantum" mean for a context switch?
Hello everyone, I can’t understand something, everywhere about the description of how context switching works, it is said about the so-called time quantum. Here's a quote from the wiki: "The kernel may take control of a running process/thread when the time quantum expires." Well, here the question arises, and the quantum of time is how much? What if I don't have enough time? And can theoretically a situation arise that, due to the load, some process will only have time to restore the registers, and will not do anything useful, that is, there will be constantly zero work during this period of time? Or are there guarantees that at least for some one final operation, but this process will "move"?
Answer the question
In order to leave comments, you need to log in
A time quantum is the time during which the OS allows a thread (process) to run continuously. After the time has elapsed, the flow is replaced by another. When it is the turn of this thread (process) to be executed again, it will again be given 1 time quantum. So don't worry about running out of time - time will always be given while the process is running.
The quantum of time in different operating systems is different, usually it is something in the range of 1-10 ms. In Linux, the quantum is dynamic, calculated based on the priority of a process - the higher the priority of a process, the more the kernel lets it work.
Do not forget that processes often themselves fall into the waiting mode and thereby prematurely complete their time quantum. This often happens, for example, when waiting for I/O operations to complete, or if a thread tries to lock a mutex, but it is already occupied, etc.
can theoretically a situation arise that, due to the load, some process will only have time to restore the registers, and will not do anything useful, that is, there will be constantly zero work during this period of time?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question