Lecture 2
Lecture 2
When the shell loaded and ran the hello program, and when the hello
program printed its message,
neither program accessed the keyboard, display, disk, or main memory
directly.
Rather, they relied on the services provided by the operating system.
We can think of the operating system as a layer of software
interposed between the application program and the hardware, as shown
in Figure 1.10.
The Operating System Manages the Hardware
The operating system achieves both goals via the fundamental abstractions
shown in Figure 1.11: processes, virtual memory, and files.
The Operating System Manages the Hardware
As this figure suggests, files are abstractions for I/O devices,
virtual memory is an abstraction for both the main memory and disk I/O
devices, and
Processes are abstractions for the processor, main memory, and I/O
devices.
The Operating System Manages the Hardware
Processes
A process is the operating system’s abstraction for a running program.
Multiple processes can run concurrently on the same system, and
each process appears to have exclusive use of the hardware.
By concurrently, we mean that the instructions of one process are
interleaved with the instructions of another process.
In most systems, there are more processes to run than there are CPUs to
run them.
The Operating System Manages the Hardware
Processes
Traditional systems could only execute one program at a time,
While newer multicore processors can execute several programs
simultaneously.
In either case, a single CPU can appear to execute multiple processes
concurrently by having the processor switch among them.
The operating system performs this interleaving with a mechanism known
as context switching.
The Operating System Manages the Hardware
Processes
The operating system keeps track of all the state information that the
process needs in order to run.
This state, which is known as the context,
includes information such as the current values of the PC, the register file,
and the contents of main memory.
At any point in time, a uniprocessor system can only execute the code for a
single process.
The Operating System Manages the Hardware
Processes
When the operating system decides to transfer control from the current
process to some new process,
it performs a context switch by saving the context of the current process,
restoring the context of the new process,
and then passing control to the new process.
The new process picks up exactly where it left off.
The Operating System Manages the Hardware
Processes
Figure 1.12 shows this basic idea.