15

Who schedules the scheduler?

Which is the first task created and how is this first task created? Isn't any resource or memory required for it? isn't like a chicken and egg scenario?

Isn't scheduler a task? Does it get the CPU at the end of each time slice to check which task needs to be given CPU?

Are there any good links which makes a person think and understand deeply all these concepts rather than spilling out some theory which needs to be byhearted?

1
  • There is not really a generic answer. You would need to look at a specific OS implementation. However, @Ira's answer is probably applicable to most OSes.
    – Benoit
    Apr 29, 2010 at 16:32

2 Answers 2

17

The scheduler is scheduled by

  • an (external) event such as an interrupt, (disk done, mouse click, timer tick)
  • or an internal event (such as the completion of a thread, the signalling by a thread that it needs to wait for something, or the signalling of a thread that it has released a resource, or a trap caused by a thread doing something illegal like division by zero)

In short, it is triggered by any event that might require that the set of tasks to be run and/or the priorities of those tasks to be reevaluated. The scheduler decides which task(s) run next, and passes control to the next task.

Typically, this "scheduling" of the scheduler is caused by the code associated with a hardware interrupt, or code associated with a system call.

While you can think of the scheduler as being a real thread, in practice it doesn't need to be implemented that way... because it is executed with higher priority than any other task. Sophisticated OSes may in fact set aside a special thread that is the scheduler, and mark it busy when the scheduler gets control. That makes it pretty, but the bogus thread isn't scheduled by the scheduler

One can have multiple schedulers: the highest priority one (e.g., the one we just described), and other schedulers which really are threads, and are run like other user tasks. Such lower priority schedulers tend to be used to manage actions which occur at much longer intervals, such as background jobs.

2
  • 5
    Agreed: The scheduler is not a task, it is a procedure that is invoked at 'scheduling points'.
    – Clifford
    Feb 12, 2010 at 9:54
  • I used to take the hardware timer interrupt as the main source to trigger the scheduler function. The schuduler function is responsible for all the task switch details, such as context swith and priority adjustment. But now I find that this would mean that task switch timing is predictable. Ira's answer is very good. Feb 26, 2010 at 15:54
2

it is usually invoked periodically by a timed CPU interrupt

1
  • 1
    I'm not sure whether this really adds to the question... there already is an answer mentioning interrupts and the question is from 2010. Feb 28, 2018 at 7:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.