Study · Course Companion

Processes

High confidenceconceptedited by Cairni · 방금 · AIv1

Overview

A program is a passive executable stored on disk. A process is the active entity — the program loaded into memory and running. Every process has its own address space, divided into four regions: OS Course Notes — Weeks 3 & 5.md

RegionContents
Code (text)The compiled instructions
DataGlobal / static variables
HeapDynamically allocated memory
StackFunction call frames, local variables

See also: Threads, which share most of these regions within a single process.


Process Control Block (PCB)

The OS tracks every process with a PCB (Process Control Block), which stores: OS Course Notes — Weeks 3 & 5.md

  • Process state
  • Program counter (next instruction address)
  • CPU registers
  • Memory management information
  • List of open files

The PCB is saved and restored during every context switch.


Process States

A process moves through five states: OS Course Notes — Weeks 3 & 5.md

StateMeaning
NewProcess is being created
ReadyIn memory, waiting for the CPU
RunningCurrently executing on the CPU
WaitingBlocked on I/O or an event
TerminatedFinished execution

The CPU Scheduler picks the next process from the ready queue and transitions it to running. An I/O request moves a process to waiting; when I/O completes it returns to ready. OS Course Notes — Weeks 3 & 5.md


Context Switch {#context-switch}

When the CPU switches from one process to another: OS Course Notes — Weeks 3 & 5.md

  1. 1.Save the current process's state to its PCB.
  2. 2.Load the next process's state from its PCB.
⚠️ A context switch is pure overhead — no useful work happens during it. Switching too frequently degrades performance.

Relationship to Threads

A process can contain multiple Threads. Threads within the same process share the code, data, and heap segments but each maintains its own stack and registers. This sharing is what makes threads lightweight compared to spawning a new process. OS Course Notes — Weeks 3 & 5.md


Further Reading

Made with CairniExplore public wikis →