1

Just a simple question: in a single-task system OS copies smt to memory and then 'goes to' somewhere there and program returns control to task manager later. But in multitasking OS we just make a few steps inside the process and than return to task manager waiting for own turn. How do we 'go to task manager' without 'goto' and 'ret's?

(The only thing that comes to mind - some strange interruption in CPU like 'have made one instruction' )

Ben Usman
  • 7,969
  • 6
  • 46
  • 66
  • It's done via interrupts. Here's an answer I posted once about how the real-time operating system vxWorks regains control and schedules a new task that might help: http://stackoverflow.com/questions/2995210/how-does-a-vxworks-scheduler-get-executed/3000034#3000034 – indiv Oct 19 '10 at 15:04
  • Talking about *go back* you should really try this `edit` button and fix the many typos from your question. – Déjà vu Oct 19 '10 at 15:05
  • @indiv Thanks a lot. Really interesting. – Ben Usman Oct 19 '10 at 15:06
  • @ring0, better this way? And does it wokrs the same way in other OS? – Ben Usman Oct 19 '10 at 15:12
  • http://superuser.com/questions/111572/how-os-manage-running-programs one more common question. – Ben Usman Oct 19 '10 at 15:24

1 Answers1

3

There are two major types of multi-tasking systems. Cooperative and Pre-emptive.

In a cooperative system each task is given control then expected to run for some period. It must then voluntarily return control to the scheduler. This may be through run-to-completion of a scheduled function or by calling a yield() function. It is possible to make the system unresponsive by executing a task that doesn't yield.

In a preemptive system the scheduler maintains full control of what task runs and for how long through enforcement of time-slicing and/or task priority. The enforcement itself is typically triggered by a system clock that generates interrupts at some fixed rate. Because of this property it is more difficult to make the system unresponsive but still possible through priority inversion or resource deadlocks.

Amardeep AC9MF
  • 18,464
  • 5
  • 40
  • 50