...

/

Problem #2: Switching Between Processes

Problem #2: Switching Between Processes

In this lesson, let's discuss how the OS regains CPU control through different​ approaches when other processes are running and how context switching takes place!

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, early versions of the Macintosh operating system"Mac OS 9" by Apple Computer, Inc… January 2011. http://en.wikipedia.org/wiki/Mac_OS_9. You can probably even find an OS 9 emulator out there if you want to; check it out, it’s a fun little Mac!, or the old Xerox Alto system"Alto User’s Handbook" by Xerox. Xerox Palo Alto Research Center, September 1979. Available: http://historycomputer.com/Library/AltoUsersHandbook.pdf. An amazing system, way ahead of its time. Became famous because Steve Jobs visited, took notes, and built Lisa and eventually Mac.) is known as the cooperative approach. In this style, the OS trusts the processes of the system to behave reasonably. Processes that run for too long are assumed to periodically give up the CPU so that the OS can decide to run some other task.

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 ...