CS 537 Notes, Section #3: Dispatching, Creating Processes


OSTEP: Chapter 4 (fork and exec).
OSTEP: Chapter 5.

How does the operating system decide which process to run next? It's a two part operation, seperating the policy (in the scheduler) from the mechanism (in the dispatcher).

Scheduler: Make decisions based on process and user priorities, and past process behavior, as to which processes to run next. We'll study this more in Lecture 11 on CPU scheduling.

Dispatcher: Implements the scheduler's decisions. This means the mechanisms to collect the necessary performance data for the schedule, quickly finding the net process to run, and actually switching to the next process.

So, how does dispatcher decide which process to run next?


Dispatcher Figure

CPU can only be doing one thing at a time: if user process is executing, dispatcher is not: OS has lost control. How does OS regain control of processor?

Internal events (things occurring within user process):

These are also called traps. They all cause a state switch into the OS.

External events (things occurring outside the control of the user process):

External events are usually called interrupts. They all cause a state switch into the OS. This means that user processes cannot directly take I/O interrupts.


When process is not running, its state must be saved in its process control block. What gets saved? Everything that next process could trash:


PCB Closeup Figure

How do we switch contexts between the user and OS? Must be careful not to mess up process state while saving and restoring it.

Saving state: it is tricky because the the OS needs some state to execute the state saving and restoring code.

Short cuts: as process state becomes larger and larger, saving and restoring becomes more and more expensive. Cannot afford to do full save/restore for every little interrupt.


Creating a process from scratch (e.g., the Windows CreateProcess):

Forking: want to make a copy of existing process (e.g., Unix/Linux).

What is missing?


Fork Figure

For an interesting perspective on fork, check out this recent paper. Note that I don't agree with many of their arguments:

Andrew Baumann, Jonathan Appavoo, Orran Krieger and Timothy Roscoe, A fork() in the Road, 18th Workshop on Hot Topics in Operating Systems (HotOS'19), Bertinoro, Italy, May 2019. https://doi.org/10.1145/3317550.3321435.



Copyright © 2018, 2020 Barton P. Miller
Non-University of Wisconsin students and teachers are welcome to print these notes their personal use. Further reproduction requires permission of the author.