Process Resources; CPU Scheduling

Tom Kelliher, CS 318

Feb. 25, 1998

Announcements:

From last time:

  1. Lamport's bakery algorithm.

  2. ``Classic'' synchronization problems.

Outline:

  1. Process resources.

  2. Process scheduling.

  3. Context switching.

  4. Process operations.

Assignment: Read Chapter 5.

Process Resources

  1. Program in execution.
  2. Serial, ordered execution within a single process. (Contrast task with multiple threads.)
  3. ``Parallel'' unordered execution between processes.

Three issues to address

  1. Specification and implementation of processes --- the issue of concurrency (raises the issue of the primitive operations).

  2. Resolution of competition for resources: CPU, memory, I/O devices, etc.

  3. Provision for communication between processes.

Process States

Three possible states for a process:

How many in each state?

A Process' Resources

Kept in a process control block (PCB) for each process:

  1. Code (possibly shared among processes).
  2. Execution stack --- stack frames.
  3. CPU state --- general purpose registers, PC, status register, etc.
  4. Heap --- dynamically allocated storage.
  5. State --- running, ready, blocked, zombie, etc.
  6. Scheduling information --- priority, total CPU time, wall time, last burst, etc.
  7. Memory management --- page, segment tables.
  8. I/O status --- devices allocated, open files, pending I/O requests, postponed resource requests (deadlock avoidance).
  9. Accounting --- owner, CPU time, disk usage, parent, child processes, etc.
Contrast program.

PCB updated during context switches (kernel in control).

Should a process be able to manipulate its PCB?

Process Scheduling

Determination of which process to run next (CPU scheduling).

Multiple queues for holding processes:

  1. Ready queue --- priority order.
  2. I/O queues --- request order.

    Consider a disk write:

    1. Syscall.
    2. Schedule the write.
    3. Modify PCB state, move to I/O queue.
    4. Call short term scheduler to perform context switch.
    Is it necessary to wait on a disk write?

  3. Event queues --- waiting on child completion, sleeping on timer, waiting for request ( inetd).

Three types of schedulers:

Long Term Scheduler

Determines overall job mix:

  1. Balance of I/O, CPU bound jobs.
  2. Attempts to maximize CPU utilization, throughput, or some other measure.
  3. Runs infrequently.

Medium Term Scheduler

Cleans up after poor long term scheduler decisions:

  1. Over-committed memory --- thrashing.
  2. Determines candidate processes for suspending and paging out.
  3. Decreases degree of multiprogramming.
  4. Runs only when needed.

CPU Scheduler

Decides which process to run next:

  1. Picks among processes in ready queue.
  2. Priority function.
  3. Runs frequently --- must be efficient.

Context Switching

Time line schematic:

Operations on Processes

Process Creation

Parent, child.

Where does the child's resources come from? By ``resources'' we mean:

  1. Stack.
  2. Heap.
  3. Code.
  4. Environment --- environment variables, open files, devices, etc.

Design questions:

Solutions to the ``copy the parent's address space'' problem:

  1. Copy on write --- Mark all parent's pages read only and shared by parent & child. On any attempted write to such a page, make a copy and assign it to child. Fix page tables.
  2. vfork --- No copying at all. It is assumed that child will perform an exec, which provides a private address space.


Thomas P. Kelliher
Mon Feb 23 08:03:04 EST 1998
Tom Kelliher