Docsity

Everything Operating Systems – Complete Summary with Algorithms & Examples (2026), Summaries of Operating Systems

Toggle sidebar
bg1
Everything Operating Systems
Complete Summary with Key Concepts, Algorithms &
Examples
Table of Contents
1. Introduction to Operating Systems
2. Processes & Threads
3. CPU Scheduling
4. Process Synchronization
5. Deadlocks
6. Memory Management
7. Virtual Memory
8. File Systems
9. I/O Systems
10. Quick Reference Tables
11. Key Takeaways
1. Introduction to Operating Systems
Definition: An Operating System (OS) is system software that manages hardware
resources and provides services for application programs. It acts as an intermediary
between the user and the hardware.
Core Functions:
● Resource Management — Allocates CPU, memory, and I/O devices among
competing processes
● Process Management — Creates, schedules, and terminates processes
● Memory Management — Tracks memory usage and allocates/deallocates
space
● File System Management — Organizes and stores data on disk
● Security & Protection — Controls access to resources
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20

Partial preview of the text

Download Everything Operating Systems – Complete Summary with Algorithms & Examples (2026) and more Summaries Operating Systems in PDF only on Docsity!

Everything Operating Systems

Complete Summary with Key Concepts, Algorithms &

Examples

Table of Contents

  1. Introduction to Operating Systems
  2. Processes & Threads
  3. CPU Scheduling
  4. Process Synchronization
  5. Deadlocks
  6. Memory Management
  7. Virtual Memory
  8. File Systems
  9. I/O Systems
  10. Quick Reference Tables
  11. Key Takeaways

1. Introduction to Operating Systems

Definition: An Operating System (OS) is system software that manages hardware resources and provides services for application programs. It acts as an intermediary between the user and the hardware.

Core Functions:

● Resource Management — Allocates CPU, memory, and I/O devices among competing processes ● Process Management — Creates, schedules, and terminates processes ● Memory Management — Tracks memory usage and allocates/deallocates space ● File System Management — Organizes and stores data on disk ● Security & Protection — Controls access to resources

● User Interface — CLI (shell) or GUI

Types of OS:

Type Description Example

Batch Executes jobs in batches without user interaction

Early IBM mainframes

Time-Sharing Shares CPU time among multiple users

Unix, Linux

Real-Time (RTOS)

Guarantees response within strict deadlines

FreeRTOS, VxWorks

Distributed Manages a network of independent computers

Google's Borg

Embedded Runs on limited-resource devices

Android, Raspberry Pi OS

Kernel: The core component of the OS that runs in privileged mode. Two main architectures:

2. Processes & Threads

2.1 Process

Definition: A process is a program in execution. It has its own memory space, program counter, registers, and stack.

Process States:

text

  1. │ New │
  2. └────┬─────┘
  3. │ admitted
  4. ▼
  5. ┌──────────┐ exit ┌───────────┐
  6. │ Ready │───────────▶│ Terminated│
  7. └────┬─────┘ └───────────┘
  8. │ dispatched
  9. ▼
  10. ┌──────────┐
  11. │ Running │
  12. └────┬─────┘
  13. │ I/O wait
  14. ▼
  15. ┌──────────┐
  16. │ Waiting │
  17. └────┬─────┘
  18. │ I/O complete
  19. ▼

(Ready)

Process Control Block (PCB): Data structure the OS uses to track a process. Contains:

● Process ID (PID) ● Process state ● Program counter ● CPU registers

● Memory management info (page tables, base/limit registers) ● I/O status (open files, devices) ● Scheduling information (priority, time remaining)

Context Switch: Saving the state of the current process (into its PCB) and loading the state of the next process. This is pure overhead — no useful work is done during a context switch.

2.2 Threads

Definition: A thread is the smallest unit of execution within a process. Threads within the same process share memory and resources but have their own stack and registers.

Process vs. Thread:

Feature Process Thread

Memory space Separate Shared (within process)

Context switch cost

High Low

Communication IPC (pipes, sockets, shared memory)

Direct (shared memory)

Isolation Strong Weak (one crash can kill the process)

3. CPU Scheduling

Purpose: Decide which process in the ready queue gets the CPU next. Maximize CPU utilization, throughput, and fairness.

Scheduling Criteria:

Criterion Description Goal

CPU Utilization % of time CPU is busy Maximize

Throughput Processes completed per time unit

Maximize

Turnaround Time Time from submission to completion

Minimize

Waiting Time Time spent in ready queue Minimize

Response Time Time from submission to first response

Minimize

3.1 Scheduling Algorithms

First-Come, First-Served (FCFS)

● How it works: Processes are executed in arrival order. Non-preemptive. ● Problem: Convoy effect — a long process at the front delays all short processes behind it. ● Example: P1 (burst 20ms), P2 (burst 3ms), P3 (burst 3ms) → avg waiting time = (0 + 20 + 23)/3 = 14.3ms

Shortest Job First (SJF)

● How it works: Pick the process with the shortest CPU burst. Non-preemptive (or preemptive = SRTF). ● Optimal for minimizing average waiting time — but requires knowing burst times in advance (impossible in practice). ● Example: Same as above → P2, P3, P1 → avg waiting = (0 + 3 + 6)/3 = 3ms

Round Robin (RR)

● How it works: Each process gets a fixed time quantum (e.g., 4ms). If not finished, it goes to the back of the queue. Preemptive. ● Trade-off: Small quantum → more context switches; large quantum → behaves like FCFS. ● Good for: Time-sharing systems, fairness.

Priority Scheduling

● How it works: Each process has a priority; highest priority runs first. ● Problem: Starvation — low-priority processes may never run. ● Solution: Aging — gradually increase priority of waiting processes.

Multilevel Feedback Queue (MLFQ)

● How it works: Multiple queues with different priorities. New processes start at the highest priority; if they use too much CPU, they are demoted. Preemptive. ● Advantage: Adapts to process behavior without prior knowledge.

4. Process Synchronization

Problem: Concurrent processes accessing shared data can cause race conditions — the output depends on the unpredictable order of execution.

Critical Section: A section of code that accesses shared resources and must not be executed by more than one process at a time.

Requirements for a solution:

  1. Mutual Exclusion — Only one process in the critical section at a time
  2. Progress — If no process is in the critical section, one waiting process must be allowed in
  3. Bounded Waiting — A process cannot be starved indefinitely

4.1 Synchronization Tools

Mutex Lock

c

  1. lock_t mutex;
  2. lock(mutex);
  3. // critical section

unlock(mutex);

● Simple, but busy-waiting (spinning) wastes CPU.

Semaphore

● Definition: An integer variable with two atomic operations: ○ wait(S) / P(S) — decrement; block if negative ○ signal(S) / V(S) — increment; wake a waiting process ● Binary semaphore (0/1) ≈ mutex ● Counting semaphore (0..N) — controls access to N resources

Example — Producer/Consumer with semaphores:

c

  1. semaphore empty = N; // number of empty slots
  2. semaphore full = 0; // number of filled slots
  3. semaphore mutex = 1; // mutual exclusion
  4. // Producer
  5. wait(empty);
  6. wait(mutex);
  7. // add item to buffer
  8. signal(mutex);
  9. signal(full);
  10. // Consumer
  11. wait(full);
  12. wait(mutex);
  13. // remove item from buffer
  14. signal(mutex);

signal(empty);

Monitor

● High-level construct — mutual exclusion is automatic; programmer doesn't manage semaphores manually. ● Uses condition variables (wait() and signal()) for synchronization.

5. Deadlocks

Definition: A set of processes are deadlocked if each is waiting for an event that only another process in the set can cause.

Four Necessary Conditions (Coffman Conditions):

  1. Mutual Exclusion — Resource is held exclusively
  2. Hold and Wait — Process holds one resource while waiting for another
  3. No Preemption — Resources cannot be forcibly taken away
  4. Circular Wait — A cycle of processes each waiting for a resource held by the next

All four must hold simultaneously for a deadlock to occur. Break any one → no deadlock.

5.1 Handling Deadlocks

Strategy Description Example

Prevention Ensure at least one Coffman condition cannot hold

Require all resources upfront (breaks hold-and-wait)

Avoidance Use advance knowledge to avoid unsafe states

Banker's Algorithm

Detection & Recovery

Allow deadlocks, detect them, then recover

Resource allocation graph cycle detection

Ignorance Ignore the problem (most OSes do this!)

Linux, Windows

5.2 Banker's Algorithm (Avoidance)

● Each process declares its maximum resource needs in advance. ● Before granting a request, the OS checks if the resulting state is safe (i.e., there exists a sequence in which all processes can finish). ● If safe → grant; if unsafe → wait. ● Limitation: Requires knowing maximum needs in advance; rarely used in practice.

5.3 Resource Allocation Graph

● Nodes: Processes (circles) and resources (rectangles) ● Edges: Request edges (P → R) and assignment edges (R → P) ● Rule: If the graph contains a cycle → potential deadlock (definite if each resource has a single instance).

6.2 Allocation Strategies

Strategy Description Problem

Contiguous Allocation

Each process gets one contiguous block

External fragmentation

Fixed Partitioning Memory divided into fixed-size partitions

Internal fragmentation

Dynamic Partitioning Partitions created on demand

External fragmentation

Fragmentation:

● Internal: Allocated memory is larger than needed (wasted inside the partition) ● External: Enough total free memory exists but not contiguous

Compaction: Shuffle memory to combine free blocks. Expensive (requires moving processes).

6.3 Paging

● Idea: Divide physical memory into fixed-size frames and logical memory into same-size pages. ● Page Table: Maps page numbers → frame numbers. ● Advantage: Eliminates external fragmentation. ● Disadvantage: Internal fragmentation (last page may be partially unused) + page table overhead.

Address Translation (Paging):

text

  1. Logical Address: [ Page Number | Offset ]
  2. │
  3. ▼
  4. Page Table Lookup
  5. │
  6. ▼

Physical Address: [ Frame Number | Offset ]

TLB (Translation Lookaside Buffer): A small, fast cache for page table entries. Dramatically speeds up address translation.

6.4 Segmentation

● Idea: Divide memory into variable-sized segments based on logical units (code, stack, heap). ● Segment Table: Maps segment number → (base, limit). ● Advantage: Matches programmer's view of memory. ● Disadvantage: External fragmentation.

Segmentation + Paging: Combine both — segments are divided into pages. Used in modern x86.

LRU (Least Recently Used)

Evict the page not used for the longest time

No

Optimal Evict the page that won't be used for the longest time

No (but requires future knowledge)

Clock (Second Chance)

Approximation of LRU using a reference bit

No

Example — Reference string: 7, 0, 1, 2, 0, 3, 0, 4 with 3 frames

Step Page FIFO Frames

Fault?

1 7 [7, -, -] ✅

2 0 [7, 0, -] ✅

3 1 [7, 0, 1] ✅

4 2 [2, 0, 1] ✅ (evict 7)

5 0 [2, 0, 1] ❌

6 3 [2, 3, 1] ✅ (evict 0)

7 0 [2, 3, 0] ✅ (evict 1)

8 4 [4, 3, 0] ✅ (evict 2)

Total faults: 7 out of 8 (FIFO is not great here).

7.3 Thrashing

● Definition: A process spends more time paging than executing. ● Cause: Too many processes → not enough frames per process → constant page faults. ● Solution: Working Set Model — track the set of pages a process is actively using; ensure enough frames for the working set. If not enough frames, reduce the degree of multiprogramming.