Notes on Process State Models and Process Management (Stallings 2018)

Process Overview and Key Elements

  • In studying operating systems, a process can be defined in several ways depending on its composition or utilization:
    • A process can be a program in execution.
    • A process can be an instance of a program running on a computer.
    • A process can be considered as an entity that can be assigned to and executed on a processor.
    • A process can be treated as a unit of activity that executes a sequence of instructions, a current state, and an associated set of system resources.
    • A process can also be defined as an environment that consists of a number of elements for executing a user-level program. (Stallings, 2018)
  • Two essential elements of a process:
    • Program code (can be shared with other processes running the same program)
    • Data associated with the program code
  • A computer's kernel can execute multiple processes at a time, supporting thousands of processes on a single system. (Gregg, 2021)
  • At any given point in time, the following elements characterize a process during execution:
    • Identifier: a unique identifier for each process
    • Process State: current activity of the process (see states below)
    • Priority: priority level relative to other processes
    • Program counter: address of the next instruction to be executed
    • Memory pointer: pointers to program code and data, including shared memory blocks
    • Context data: data present in the processor's registers during execution
    • I/O status information: outstanding I/O requests and I/O devices assigned to the process
    • Accounting information: processor time, clock time used, time limits
  • The elements of a process are stored in a data structure called the Process Control Block (PCB).
    • The PCB enables interrupting a running process and resuming it later as if uninterrupted, making multiprocessing possible. (Stallings, 2018)
  • Process definitions and taxonomy are foundational for understanding OS scheduling, dispatching, and resource allocation.

Two-State Process Model (Stallings, 2018)

  • A process is either in the Not running state or the Running state.
    • Not running state: when the OS creates a new process, it creates the PCB and places the process into the not running state, awaiting an opportunity to execute.
    • Running state: the dispatcher selects a process to run and enters the running state.
    • Interruption: the currently running process may be interrupted; the dispatcher selects another process to run, and the interrupted process returns to the not running queue. A completed process exits the system.
  • The state transition is typically depicted in Figure 1 (Source: Stallings, 2018).
  • Limitations of the two-state model:
    • It assumes all processes are always ready to execute.
    • The not running queue is FIFO; each process receives a fixed timeslice and then returns to the queue unless completed.
    • Some processes in the not running state are blocked waiting for I/O.
    • With a single queue, the dispatcher would have to scan the queue to find a non-blocked process that has been waiting the longest, which is inefficient.
    • This makes the two-state model inadequate for real systems.

Five-State Process Model (Stallings, 2018)

  • This model introduces five states to better reflect real system behavior:
    • New: a process that has just been created and is not yet admitted to the executable pool.
    • Ready: a process prepared to execute when given the opportunity.
    • Running: the process currently being executed.
    • Blocked/Waiting: a process that cannot execute until some event occurs (e.g., I/O completion).
    • Exit: a process released from the executable pool (terminated or halted).
  • Relationship to the two-state model:
    • The not running state from the two-state model is effectively split into Ready and Blocked in the five-state model.
    • New and Exit are added as management constructs for process lifecycle.
  • Possible state transitions (representative list):
    • Null
      ightarrow New
    • New
      ightarrow Ready
    • Running
      ightarrow Exit
    • Blocked
      ightarrow Ready
    • New
      ightarrow Ready
    • Running
      ightarrow Ready
    • Ready
      ightarrow Exit
    • Ready
      ightarrow Running
    • Running
      ightarrow Blocked
    • Blocked
      ightarrow Exit
  • Suspended Processes (Stallings, 2018): Some OSs include a suspended state in addition to the three principal states to cover processes not immediately available for execution.
    • A suspended process may or may not be waiting for a specific event; if blocked, the blocking event does not automatically enable immediate execution.
    • Reasons to suspend a process include:
    • a) The process itself
    • b) A parent process
    • c) The operating system
  • Figure 3 conceptually shows a five-state model with a suspended state.

Three Principal States and Rationale

  • The three principal states, commonly modeled in OS implementations, are:
    • Ready
    • Running
    • Blocked
  • Why these three states? They provide a systematic way of modeling a process and guide the OS implementation; some OSs use only these three states.

Process Description (Stallings, 2018)

  • Role of the Operating System (OS): controls all events in a computer system, schedules and dispatches processes for execution, allocates resources, and responds to requests for basic services from user processes.
  • In a multiprogramming environment with virtual memory, many processes can exist; the OS must maintain information about the status of each process and its resources to manage operations effectively.
  • Four types of tables maintained by the OS: 1) Memory tables: track main and secondary memory; a portion of main memory is reserved for OS use; the rest is available to processes.
    • Memory management information includes:
      • Allocation of main memory to processes
      • Allocation of secondary memory (virtual memory) to processes
      • Protection attributes for main/virtual memory
      • Information needed to manage virtual memory
        2) I/O tables: manage input and output devices and channels at any given time.
        3) File tables: hold information about files and their attributes via the file management system.
        4) Process tables: maintained to manage processes.
  • Process Location and Image:
    • A process must include a program to be executed and a data location for local/global variables and constants.
    • A process encompasses sufficient memory to hold its program and data.
    • Process Control Blocks (PCBs) are also referred to as process images.
    • The location of a process image depends on the memory management scheme used.
    • In the simplest case, a process image is a continuous block on secondary memory; to execute, the entire image must be loaded into main memory or a virtual memory.
    • The OS needs to know the location of each process on disk.
  • Process Attributes (three categories in the PCB):
    1) Process identification: unique numeric identifiers; can be an index into a primary process table or cross-referencing identifiers.
    2) Processor state information: contents of processor registers; when interrupted, register contents must be saved for later restoration.
    3) Process control information: additional data needed by the OS to control and coordinate processes (data structures, resource ownership, utilization information, privileges).
  • Importance of the PCB: The PCB is the most important data structure in OSs; it is read and/or modified by every module involved in resource allocation, scheduling, interrupt processing, analysis, and performance monitoring.

Process Control (Stallings, 2018) Modes of Execution

  • User mode: the less-privileged mode; user programs execute in this mode.
  • Kernel mode: the more-privileged mode; the OS has complete control of the processor, its instructions, registers, and memory.
  • Privilege separation protects the OS and critical OS tables, such as process control blocks, from interference by user programs.

Process Creation

  • When a new process is to be added, the OS builds the data structure to manage the process and allocates address space in main memory.
  • Modern OS often create processes transparently to the user or application program.
  • It can be useful to allow one process to cause the creation of another process.
  • Typical steps for process creation:
    1) Assign a unique process identifier to the new process
    2) Allocate space for the process
    3) Initialize the process control block
    4) Set the appropriate linkages
    5) Create or expand other data structures as needed

Process Switching

  • Process switching (context switching) can occur at any time as the OS reclaims control.
  • Involves interrupts or traps:
    • Interrupts: external events independent of the currently running process.
    • Traps: errors or exception conditions generated within the currently running process.
    • Supervisor calls: explicit requests to perform OS services that interrupt process execution.
  • The OS saves the state of the preempted process and loads the state of the next one.

Process Termination

  • OS must provide a mechanism for a process to indicate its completion:
    • A batch job may include a halt instruction or an explicit OS service call for termination.
    • The halt instruction typically generates an interrupt to alert the OS that a process has finished.
    • For interactive applications, user actions can trigger termination.
    • In some OSs, a process can be terminated by the process that created it, or when the parent process is terminated.

References

  • Gregg, B. (2021). System performance: Enterprise and Cloud (2nd ed.). Pearson Education, Inc.
  • Silberschatz, A., Galvin, P. & Gagne, G. (2018). Operating systems concepts (10th ed.). John Wiley & Sons, Inc.
  • Stallings, W. (2018). Operating systems: Internal and design principles (9th ed.). Pearson Education Limited