Process Life Cycle
Process states: New Ready Running Waiting Terminated
Process Life Cycle
Five states a process moves through during execution
New: being created. Ready: waiting for CPU. Running: executing. Waiting: blocked (e.g., waiting for disk). Terminated: finished. Scheduler moves processes between Ready and Running.
Deadlock Conditions
Deadlock requires all 4: Mutual exclusion, Hold-and-wait, No preemption, Circular wait
Deadlock Conditions
Four conditions that must ALL be present for a deadlock
Remove any one condition â prevent deadlock. Mutual exclusion: only one process uses resource at a time. Hold and wait: holds resource while waiting for another. No preemption: can't forcibly take resources. Circular wait: chain of processes each waiting on the next.
Virtual Memory
Virtual memory: OS swaps pages to disk â programs see more RAM than exists
Virtual Memory
The OS gives programs the illusion of abundant memory
OS uses disk as overflow when RAM fills up. Programs see a large contiguous address space. Page fault: needed page not in RAM â load from disk (slow). Paging: fixed-size blocks.
Scheduling Algorithms
CPU Scheduling: FCFS, SJF, Round Robin, Priority
Scheduling Algorithms
How the OS decides which process gets CPU time
FCFS: first come first serve â simple, long jobs block short ones. SJF: shortest job first â minimizes wait, needs job-length prediction. Round Robin: each gets a fixed time slice â fair. Priority: highest priority runs first.
Thrashing
Thrashing: too many processes â constant page swapping â CPU spends all time on I/O, none on work
Thrashing
When virtual memory page swapping overwhelms the CPU
Occurs when the total working set of all processes exceeds available RAM. OS spends more time swapping pages than running processes. Solution: reduce multiprogramming degree or add RAM.
File Systems
File systems: FAT32 (simple, compatible), NTFS (Windows, journaling), ext4 (Linux), APFS (Apple)
File Systems
How operating systems organize and store data on disk
File system: organizes data on storage devices. FAT32: simple, max 4GB file size, universal compatibility. NTFS: Windows, journaling (recovers from crashes), large files, permissions. ext4: Linux standard, journaling, large file support. Hierarchical structure: root â directories â files. Inodes: metadata about files (not content).
Memory Hierarchy
Memory hierarchy: registers â cache (L1/L2/L3) â RAM â SSD â HDD. Faster = smaller and more expensive.
Memory Hierarchy
The pyramid of memory â speed vs capacity vs cost
Registers: fastest, inside CPU, tiny (bytes). L1 cache: ~32KB per core, ~1ns. L2 cache: ~256KB, ~4ns. L3 cache: shared, ~8MB, ~40ns. RAM: ~16GB typical, ~100ns. SSD: ~1TB, ~100Ξs. HDD: ~4TB, ~10ms. OS and hardware move data up the hierarchy (caching) to match speed with usage patterns.
Context Switching
Context switch: OS saves current process state, loads another process state â enables multitasking
Context Switching
How the OS rapidly switches between processes to simulate multitasking
When CPU switches from one process to another: save current process's registers, program counter, and state to PCB (Process Control Block). Load next process's saved state. Context switches are expensive (~microseconds) â too many degrade performance. Threads have lighter context switches than processes.
Semaphores and Synchronization
Semaphore: integer variable for synchronization. mutex (binary semaphore). P() = wait. V() = signal.
Semaphores and Synchronization
How processes coordinate access to shared resources
Semaphore: integer variable â P() decrements (wait if 0), V() increments (signal). Binary semaphore (mutex): 0 or 1, implements mutual exclusion. Counting semaphore: tracks available resources. Dining philosophers problem: classic deadlock scenario. Monitor: higher-level synchronization construct.
Paging
Paging: divide memory into fixed-size pages. Page table maps virtual to physical addresses.
Paging
How virtual memory is divided into manageable chunks
Page: fixed-size block of virtual memory (typically 4KB). Frame: corresponding physical memory block. Page table: maps virtual page numbers to physical frame numbers. Page fault: accessing page not in RAM â OS loads from disk â slow. Working set: set of pages process needs â keep in RAM to minimize page faults.
I/O Management
I/O management: buffering (temporary storage), spooling (queue for slow devices), interrupts (device signals CPU)
I/O Management
How the OS handles input and output efficiently
Busy waiting (polling): CPU repeatedly checks if I/O is done â wastes CPU cycles. Interrupts: device signals CPU when I/O complete â CPU does other work meanwhile. DMA (Direct Memory Access): device transfers data directly to memory without CPU involvement. Buffering: temporary storage to handle speed mismatch.
Shell and Scripting
Shell: command-line interface to OS. Script: sequence of commands in a file. Pipe: output of one command as input to next.
Shell and Scripting
The command-line interface and automation
Shell: program that interprets commands â bash, zsh, PowerShell. Pipe (|): chain commands, output of one â input of next. cat file | grep 'error' | wc -l. Redirection: > (output to file), < (input from file), >> (append). Shell scripts: automate repetitive tasks. Environment variables: KEY=value, PATH determines where programs are found.