Processes
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
| Region | Contents |
|---|---|
| Code (text) | The compiled instructions |
| Data | Global / static variables |
| Heap | Dynamically allocated memory |
| Stack | Function 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
| State | Meaning |
|---|---|
| New | Process is being created |
| Ready | In memory, waiting for the CPU |
| Running | Currently executing on the CPU |
| Waiting | Blocked on I/O or an event |
| Terminated | Finished 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.Save the current process's state to its PCB.
- 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
- Threads — execution units inside a process
- CPU Scheduling — how the OS picks which process runs next
- Key Concepts Glossary — one-line definitions for PCB, context switch, and more
- Exam Prep — Midterm — practice questions and checklist
- Course Overview — full topic index