- Multiprogramming: CPU (or CPUs) switch rapidly between running processes.
- Pseduoparallelism: The appearance of multiple processes running at once.
- Allows use of CPU and I/O devices in parallel.
- Supports interactive computing.
- A program in execution
- A program and an execution context.
- Execution context is all its data.
- Including the CPU state.
- Especially including the PC.
- From various viewpoints.
- Process switching.
- OS is invoked by interrupt or syscall.
- Save CPU registers, including PC and stack pointer.
- Hardware saves some at interrupt or syscall.
- O/S must save the rest.
- Update VM tables (Ch. 3).
- Update OS records. Process state and history.
- Process Creation.
Ultimately, only the kernel creates processes, often on request by
some process.
- At system initialization.
- Spawned by an existing process.
- Created by user command (probably processed by some shell process).
- Batch job submission.
- Process Termination.
- Normal exit (voluntary).
- Abnormal exit (voluntary).
- Fatal error (involuntary).
- Killed by another process (involuntary).
- Process Hierarchies.
- Unix: family tree.
- Processes are parents and children.
- Process 1 (init) is the ancestor of all.
- Init inherits orphans.
- Windows.
- Creators have a handle to processes they create.
- But can pass it to any other process: Needn't maintain the tree.
- Process states.
- The OS changes the state of a process.
- Reasons for transitions.
- This is the simplest diagram: Most real OSes divide some states into
several.
- Unix divides Blocked into long-term and short-term waits.
- Windows divides Ready to designate a next-up.
- Process table.
- OS bookkeeping: A table of running processes.
- Each entry is a record (think C struct)
containing bookkeeping data for one process.
- Process id, ownership, permissions.
- Scheduling parameters.
- Resources (memory blocks, stack location, open files).
- Register save area.
- Sometimes called a Process Control Block (PCB).
- Creation primitives.
- Windows CreateProcess.
- Creates a new process running a specified program.
- Gobs of parameters (if one gob is five).
- Returns handle used for future operations.
- Unix fork
and exec.
- Fork creates a copy of the parent process. Returns twice,
once in parent and once in child.
- Exec runs the specified program in the current process and
does not return.
- Process can make modifications between fork and exec.
- Process creation examples,
plain C,
C++.
- CPU Utilization.
- A process spends some percentage of time running on a CPU, and some
time waiting for an I/O device.
- Ideally, four processes which use the CPU a quarter of the time will
keep the CPU busy.
- Actually, they may all want to wait at the same time.
- Suppose p is the fraction of time a process spends waiting for I/O.
- The probability that all n processes are waiting is pn,
so the probability that at least one isn't will be 1−pn.
That is the
expected utilization of a single CPU.
- The number of programs in memory at once is the “degree of
multiprogramming.”