Chapter 3
Process Description and Control


Processes -- Introduction

What is a process?

The notion of a process was introduced by the developers of the Multics operating system in 1965 to denote "the execution of a program." A program is a static thing, basically just some text. However, executing the program involves not only its text, but also a sequence of operations performed based on that text, the memory used to store the text and perform the operations, etc.

The Multics authors tried to give a precise definition of a process, but most textbook authors have given more intuitive definitions, all of which emphasize the dynamic nature of a process, as opposed to the static nature of a program.

Some of these definitions:

The important points are:

  • A process is an execution stream in a particular context.
    1. The context is everything that can affect, or be affected by, the process: code, particular data values, open files, etc.

    2. The execution stream is a sequence of instructions performed using that context.

  • Processes are sequential: only one thing happens at a time.


    Process States

    The Two-State Model

    Figure 3.4 goes here.

    The Dispatcher

    The Dispatcher is the inner-most portion of the O/S; it selects and runs processes:

    1. Run a process for a while.

    2. Save the process state.

    3. Load state of another process.

    4. Run it ...

    The Two-State Model Is Inadequate

    The two-state model is not realistic. Not all processes are always ready to execute. Some processes in the Not-Running state are ready to run; others are blocked while waiting for an I/O to complete.

    Do we want to keep all these processes on a single queue? No. The Dispatcher would have to scan the Not-Running queue looking for a process that is not blocked. We'd rather have the Dispatcher just take the first process on the queue. Less overhead.

    It's more natural to separate the Not-Running state into two states: Ready and Blocked.

    The Five-State Model A process is in one of five states:

    Figure 3.5 goes here.

    Figure 3.6 goes here.


    Process Control

    Introduction


    The Process Control Block

    First, the O/S has to keep track of all the processes. For each process, the process control block (PCB) holds:

    Process Identification Information

    Processor State Information

    Process Control Information

    The Process table is a collection of all process control blocks for all processes. In Unix the process table is a fixed-size array.


    Process Switching

    CPU can only be doing one thing at a time: if user process is executing, Dispatcher isn't: O/S has lost control! How does O/S regain control of processor?

    Saving the Process State

    When a process isn't running, its state must be saved in its PCB. What gets saved? Everything that next process could damage:

    Saving the state of user process is tricky because the the O/S needs some state to execute the state saving and restoring code. All machines provide some special hardware support for saving and restoring state.

    Mode Switching

    What does the CPU do when a trap or interrupt occurs?

    1. Save the current processor state.

    2. Set the program counter to the beginning of an interrupt handler routine.

    3. Switch from user mode to kernel (supervisor, privileged) mode. Why? Interrupt handler may include privileged instructions.

    4. Begin processing interrupt handler routine.

    Interrupt Handler

    What does the interrupt handler do? It depends.