Dulranga's Notes
Semester 3Operating SystemsProcess Management

Introduction

Program - sits in hard-drive, does nothing, passive entity Process - sits in RAM, actively being loaded and executed

Program vs. Process

AttributeProgramProcess
NaturePassive entity (file stored on disk)Active entity (running in memory)
LifespanPermanent until deletedTemporary (created, executed, terminated)
Resource NeedsOnly disk storage spaceCPU time, RAM, I/O devices, registers
MultiplicityOne program file on diskCan spawn multiple concurrent processes

Memory Layout of a Process

process-structure-2.png

process-structure.png

  1. Text Segment (Code): Contains the compiled machine code instructions executed by the CPU. This segment is typically read-only to prevent accidental modification.
  2. Data Segment: Holds global and static variables.
    • Initialized Data: Variables explicitly initialized in code (e.g., int x = 10;).
    • Uninitialized Data (BSS): Global/static variables initialized to zero by default.
  3. Heap: Dynamically allocated memory at runtime (e.g., using malloc() in C or new in C++/Java). The heap grows upward toward higher memory addresses.
  4. Stack: Temporary storage for function calls, local variables, parameter passing, and return addresses. The stack grows downward toward lower memory addresses.

Process Control Block (PCB)

This contains all details about the process. This is like a blueprint.

  • Process ID (PID): A unique identifier assigned to the process.
  • Process State: Current state (e.g., Ready, Running, Waiting).
  • Program Counter (PC): Points to the address of the next instruction to execute.
  • CPU Registers: Saved register contents when the process is context-switched out.
  • CPU Scheduling Info: Priority level, scheduling queue pointers, and accounting stats.
  • Memory Management Info: Page tables or segment tables for mapping virtual to physical memory.
  • I/O Status & Open Files: List of open file descriptors and allocated I/O devices.

Process States & Lifecycle

process-lifecycle.png

  • new, ready, running, terminated are self explanatory.
  • waiting happens when the process request some user input, hard-disk read, or waiting for another process to complete (join concept at the end of main thread)

On this page