As far as I understand by reading some SO questions and the kernel docs, in Linux, a task (thread, process, or even a group of tasks) is allowed to execute without interruption during a minimum amount of time (3ms in my laptop according to /proc/sys/kernel/sched_min_granularity_ns), after which it can be stopped anytime if the load is high. If that's not the case and that CPU time has been exceeded, the task must be stopped to allow other tasks to progress.
But in my understanding, once the CPU is running a task nothing can stop it, which naturally gives birth to two very related questions:
- how can a task be stopped? the only thing I can think of is by the OS sending some simple CPU interruption of some sort, or is there anything more complex involved here?
- if the CPU is single-threaded and can only execute one task at a time, can tasks be stopped at all? because if the CPU is currently running a task, how could Linux possibly execute their own management routines to check if the task must be stopped?