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