How CPU decides when to switch to an operating system from a process?

Hello, everybody.
I have a question.
As far as I know modern operating systems use a CPU in two modes: a kernel(full access) mode and a user mode(restricted).
But how does a CPU decide when to switch to kernel code which is responsible for checking process' priorities and
deciding if currently running process have used all of it's allowed CPU's time? Sorry for my english if it is bad. Does all CPUs have
a kind of hardware timer that triggers all the time and replaces currently running user-mode code with a piece of an operating system's kernel code
in order to check processes' priorities, etc? Thanks :)
Last edited on
Does all CPUs have a kind of hardware timer that triggers all the time and replaces currently running user-mode code with a piece of an operating system's kernel code in order to check processes' priorities, etc?


Yes, that is a decent summary of what takes place. Hardware interrupts, including timer ticks, are serviced in kernel mode, at which time it can do housekeeping, including spontaneous rescheduling if the OS scheduler policy requires it.
Thank you very much. Now I will start reading docs for a particular CPU :)
Very often the process itself triggers to go into kernel mode by calling a software interrupt directly by invoking a syscall or indirectly, e.g. when accessing a memory page that was not found in TLB.
Topic archived. No new replies allowed.