
























Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!

























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:
Definition: A process is a program in execution. It has its own memory space, program counter, registers, and stack.
Process States:
text
(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.
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)
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
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.
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:
Mutex Lock
c
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
signal(empty);
Monitor
● High-level construct — mutual exclusion is automatic; programmer doesn't manage semaphores manually. ● Uses condition variables (wait() and signal()) for synchronization.
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):
All four must hold simultaneously for a deadlock to occur. Break any one → no deadlock.
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
● 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.
● 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).
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).
● 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
Physical Address: [ Frame Number | Offset ]
TLB (Translation Lookaside Buffer): A small, fast cache for page table entries. Dramatically speeds up address translation.
● 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).
● 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.