Problem #2: Switching Between Processes
Explore how operating systems manage the challenge of switching between running processes. Understand cooperative and non-cooperative scheduling approaches, how the OS regains CPU control using system calls and timer interrupts, and the role of context switching in safely saving and restoring process states.
We'll cover the following...
The next problem with direct execution is achieving a switch between processes. Switching between processes should be simple, right? The OS should just decide to stop one process and start another. What’s the big deal? But it actually is a little bit tricky: specifically, if a process is running on the CPU, this by definition means the OS is not running. If the OS is not running, how can it do anything at all? (hint: it can’t) While this sounds almost philosophical, it is a real problem: there is clearly no way for the OS to take an action if it is not running on the CPU. Thus we arrive at the crux of the problem.
THE CRUX: HOW TO REGAIN CONTROL OF THE CPU
How can the operating system regain control of the CPU so that it can switch between processes?
A cooperative approach: wait for system calls
One approach that some systems have taken in the past (for example,
Thus, you might ask, how does a friendly process give up the CPU in this utopian world? Most processes, as it turns out, transfer control of the CPU to the OS quite frequently by making system calls, for example, to open a file and subsequently read it, or to send a message to another machine, or to create a new process. Systems like this often include an ...