Skip to main content

10. Process Models and Scheduling

Real Time Operating Systems (RTOS)

Process Information

Process Image

  • Refers to the snapshot of a process’ state at a specific point in time
  • Contains all necessary information for the process to execute:
    • User memory: stack, heap, code segment, .bss
    • Process Control Block (PCB): data needed to control the process
    • Assuming VM provides separation and swapping
  • Must be (at least partially) loaded in main memory to execute
  • i.e., Process image is essential for OS to control and manage process effectively

Process Control Block (PCB)

  • Contains essential information about a process, including:
    • Registers (program counter, status word, etc.)
    • FPU state
    • Descriptor tables (e.g., IDT — Interrupt Descriptor Table)
    • Memory pointers to code and data, shared memory blocks
    • Fault handler
    • Flags
    • Process Identification: PID, parent, descendants, user
    • Processor state: PCB: registers, status word
    • Process information:
      • Process information (state, priority, event)
      • Signals and Timers
      • Credentials
      • File descriptors
      • System call vector
  • Serves as a data structure that holds all necessary details for the OS to manage and control the process effectively

Process Creation

process_creation.png{width=200px}

  1. Building the PCB to store process information
  2. Allocate memory for the process to execute
  3. Create an execution context (thread) for the process
  4. Run the process

Process Switch

  • Saves context of currently running process into PCB
  • Updates process with new state and accounting information
  • Moves process to appropriate queue (ready, blocked, etc.)
  • Selects another process to continue its execution
  • Updates MMU (Memory Management Unit)
  • Restores PCB of selected process to continue execution
  • i.e., allows OS to efficiently manage multiple processes by switching between them to utilise system resources effectively

Process Termination

process_termination.png{width=200px}

Occurs when a process exits due to reasons such as:

  • Calling exit(2) function
  • Receiving a SIGKILL signal
  • Encountering an unhandled signal
  • Exceeding resource limits

Queueing Model

queueing_model.png{width=400px}

Analysis and optimisation of processes waiting to be executed

Process models

  • Progresses from simple to realistic process execution models.

Two-state model:

  • Simplest process model; divides process execution into two states:
    • Running
    • Exit
  • In this model, a process is either actively running, or has been terminated.
    two-state_model-01.png{width=500px}
    two-state_model-02.png{width=500px}

Five-state model:

five-state_model.png{width=600px}

  • New: Created but not ready to execute
  • Ready: Can execute when scheduled by the OS
  • Running Actively executing
  • Blocked: Waiting for an event (e.g., I/O completion)
  • Exit: Terminated but metadata remains in memory

Process State Transitions

  • Defines the movement of a process from one state to another:
    • Null \to New: Process creation
    • New \to Ready: OS prepared to make process runnable
    • Ready \to Running: Dispatch ready process to execute
    • Ready \to Exit: Terminated by other process (e.g., parent)
    • Running \to Exit: Termination
    • Running \to Ready:
      • Process has had its time continuously running
      • Higher priority process has become ready — preemption
      • Voluntary yield (e.g., sleep(3), nanosleep(2))
    • Running \to Blocked: Process waits for syscall, I/O, etc.
    • Blocked \to Ready: Event that process is waiting for occurs
    • Blocked \to Exit: As above

Seven-state model:

seven-state_model.png{width=600px}

  • A more detailed representation of process behaviour, including specific conditions and events for transitions between states
  • Introduces additional process state transitions:
    • Ready \to Suspend: Manual suspension (SIGSTOP or SIGTSTP)
    • Suspend \to Ready: No ready process or suspended process has highest priority
    • Blocked \to Blocked/Suspend: Manual suspension (SIGSTOP or SIGTSTP)
    • Blocked/Suspend \to Suspend: Event being waited for occurs
    • New \to Ready/Suspend: Depends on available resources
    • Blocked/Suspend \to Blocked: Higher priority than any in Ready queue; resources available
    • Running \to Ready/Suspend: Pre-empted by Suspended process and memory ended
    • Any \to Exit: Termination

Reasons for suspension:

Lists various reasons for process suspension.

ReasonComment
SwappingOS needs to release resources for another process
User Requeste.g., debugging or manual suspension (Ctrl+Z)
TimingSuspension of periodic process while awaiting next run
Parent RequestDebugging, examination, coordination of descendants