Today's plan
- processes
- process table
- schedulers
- interrupts and context switch
- layered operating system
Processes
- a program execution is a process
- naturally, a given program may be executed more than once,
even simultaneously
- for a program to execute, it must have its own variables,
return address, etc, so all these are part of a process
- however, some programs need to create multiple processes
to run at the same time, e.g. a producer and a consumer of
information
- multiple parts of a program running at the same time still
need independent local variables and return addresses, but could:
- share global variables and other global resources, e.g.
file descriptors: threads within a process
- not share global variables/resources: separate processes
- switching among threads within a process takes less work
than switching among processes, so threads are also thought of as
lightweight processes
- switching among threads may take less time than a context switch,
so user-space threads may have extremely fast context switch
- on the other hand, if a kernel-space thread blocks doing I/O,
the kernel can wake up another thread. This is difficult with user-space
threads
Process Table
- a machine with a single process can simply execute that code
- with multiple processes, the operating system must switch
from one to the other
- to do this, the OS maintains a process table containing
values relevant to each process, including stack pointer and register
values needed to restart the process
- one field of each entry in the table stores the state
of each process, typically including:
- running, the currently running process
- ready, a process that could be selected for running
- blocked, a process that cannot run until some external
condition is met, e.g. data is available from the disk or the network
(different blocked states can be used for different conditions)
- exited, a process whose data is still in the process
table but which is no longer executable
- other data in the process table may include accounting (time/memory
used), process ID, current directory, etc
Schedulers
- once a process blocks, another must be started
- to minimize latency, different processes should be given the CPU
on a quick rotation even if they do not block
- a timer interrupt fires on a regular basis so the operating
system can make the current process ready and select
another ready process to be current
- either way, a program must select a new ready process. This code
is called the scheduler
- if there are no ready processes, the scheduler must run the null
process (an infinite loop, or setting the processor to a low-power mode)
- if there is only one ready process, the scheduler selects it
- if there are multiple ready process, the scheduler must select one
of them
Scheduler Operation
- when a timer interrupt fires, the hardware saves a few registers
(including the PC) onto the current stack and loads the PC with a
fixed address. This address may depend on which device interrupted,
in which case a number associated with the device is used as an index
into the interrupt vector
- the software in the interrupt handler must first save the
remaining registers (including the stack pointer), so they can be
restored when resuming the program. This must be done in assembler
- the software in the interrupt handler can now handle the interrupt
- after doing the device driver operations needed to handle the
interrupt, the interrupt handler can now call the scheduler to figure
out which process to restart
- the scheduler must reload all the registers (stored in the process
table), and execute a return-from-interrupt instruction (or a return
instruction) to start the new current process
A Layered Operating System
- (book, figure 2-3)
- lowest layer contains scheduler and interrupt handlers that do the
least possible to handle devices, as well as a mechanism to allow
communication among processors
- all other services, including file systems, networking protocols,
etc are separate processes
- to handle a disk interrupt, the disk interrupt handler builds
a message and "sends" it to to file system manager
- if the file system manager was waiting for a message, it now
becomes ready
- if the file system manager had high priority, the scheduler
now makes it the current process (unless another process has more
priority)
- the file system manager therefore executes quickly after the
interrupt, perhaps issuing another message to a process that had
performed a read system call
- a system like this is a microkernel system
- a famous early microkernel was Mach 3.0
- L4 is a currently popular microkernel, you can run a modified
Linux on top of it
Operating System Structures
- a monolithic kernel is a single program. No message
passing is needed, procedure calls are enough. Linux follows this model
- a microkernel has a "small-as-possible" kernel, and all other
services are implemented as processes. Minix follows this model
- a virtual machine provides multiple computing environments
equivalent to actual computers by responding appropriately when a "user
program" performs a privileged operation. The instruction set of the virtual
computer may be the same as of the actual computer (VMWare, Plex86), or
independent (Bochs)
In-class exercise
- in small groups (2-3) discuss what it would take to migrate
a process across a network to a different computer.
- why would this be useful?
- what issues arise?
- might security be an issue?
- discussions and presentation of conclusions in the last 5 minutes (if
time allows)
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 2.5 License.