Menu

Earn Premium with Referrals

Invite your friends and earn Premium rewards through our referral program.

See how it works and start inviting friends.

Part 4: File Systems, I/O & Virtualization
OS

Part 4: File Systems, I/O & Virtualization

Review file systems, inodes, disk scheduling, I/O systems, virtualization, containers, OS security, and advanced kernel concepts.

1. The Kernel Architecture

The kernel is the core of the OS. How you design it dictates the entire system’s reliability and performance.

  • Monolithic Kernel: All OS services (file system, drivers, memory management, scheduling) run in a single, large address space in kernel mode.

  • Pros: Extremely fast (no overhead for inter-module communication).

  • Cons: A bug in a single driver (like a printer driver) can crash the entire system. (Examples: Linux, older Windows).

  • Microkernel: Keeps the kernel as small as possible. Only essential services (IPC, basic scheduling, memory management) run in kernel mode; others (file systems, device drivers) run as “user-space” processes.

  • Pros: Highly modular, secure, and stable (if a driver crashes, you just restart that process).

  • Cons: Slower due to frequent message passing between services. (Examples: QNX, Minix, L4).

2. Virtualization: VMs vs. Containers

Understanding the difference between these is essential for any cloud or DevOps-related technical interview.

  • Virtual Machines (VMs): Each VM includes a full “Guest OS.” It uses a Hypervisor to virtualize hardware.

  • Isolation: High security (each VM is completely separated).

  • Cost: High overhead (CPU, RAM, and Disk space for every OS instance).

  • Containers: Containers share the “Host OS” kernel. They virtualize the user-space/libraries.

  • Isolation: Lower than VMs; they share the same kernel, so a kernel exploit could potentially affect all containers.

  • Cost: Extremely low overhead; they start in milliseconds.

  • Hypervisor Types:

  • Type 1 (Bare Metal): Runs directly on the hardware (e.g., Xen, VMware ESXi). Used in data centers.

  • Type 2 (Hosted): Runs on top of a host OS (e.g., VirtualBox, VMware Workstation). Used for testing/development.

3. File System & Storage

How does the OS remember where your file is?

  • Inodes (Index Nodes): Used in Unix-based systems. An inode contains metadata about a file (permissions, owner, size, location) but not the file name (which is stored in a directory file).
  • File Allocation Methods:
  • Contiguous: a file in one block run — fast sequential access, but external fragmentation and files can’t grow.
  • Linked: each block points to the next — no fragmentation, but only sequential access and one bad block breaks the chain.
  • Indexed: an index block lists all data-block pointers — direct random access, slight overhead for the index.
  • Hard Link vs. Soft (Symbolic) Link:
  • Hard Link: A new directory entry pointing to the same inode. If you delete the original file, the hard link still works because the data remains.
  • Soft Link: A special file that contains the path to another file. If the original file is deleted, the soft link becomes “broken” (dangling).

4. Disk Scheduling: SCAN & C-SCAN

  • SCAN (Elevator Algorithm): The disk arm moves across the disk in one direction, servicing requests, then reverses. It prevents the starvation of outer tracks, unlike FCFS.
  • C-SCAN (Circular SCAN): Similar to SCAN, but only services requests in one direction and then quickly resets to the beginning. This provides a more uniform wait time.

Worked Example

Given: head starts at cylinder 50, requests {98, 183, 37, 122, 14, 124, 65, 67}, disk spans 0–199, head initially moving toward higher cylinders.

SCAN: service 50 → 65 → 67 → 98 → 122 → 124 → 183, then reverse: → 37 → 14.

|50|65|67|98|122|124|183|---reverse---37|14|

Total head movement = (183 − 50) + (183 − 14) = 133 + 169 = 302 cylinders.

C-SCAN: service 50 → 65 → 67 → 98 → 122 → 124 → 183, then jump back to 0 and service: → 14 → 37. Total head movement = (183 − 50) + (183 − 0) + (37 − 14) = 133 + 183 + 23 = 339 cylinders.

  • C-SCAN moves further (the reset is a full sweep) but gives more uniform wait times — that’s why it’s often preferred over plain SCAN in real disks.

5. RAID Levels

  • RAID 0 (Striping): data split across disks, no redundancy. Max speed and capacity, but any disk failure loses everything.

  • RAID 1 (Mirroring): identical copies on two disks. Full redundancy, read speedup, but 2× storage cost.

  • RAID 5 (Striped Parity): data + distributed parity across ≥3 disks; survives one disk failure, efficient use of space.

  • RAID 6 (Dual Parity): survives two failures; needs ≥4 disks.

  • RAID 10 (0+1): striping + mirroring — speed and redundancy, but expensive.

  • Rule of thumb: RAID 0 = speed, RAID 1 = safety, RAID 5 = balanced (one fault tolerant), RAID 6 = two-fault tolerant.

6. Interrupts & DMA

  • Interrupt types: hardware (device signals the CPU), software/trap (program does an illegal op or a system call), exception (e.g., divide-by-zero). Each has an interrupt vector.
  • ISR flow: CPU finishes current instruction → saves state (registers/PC) → looks up the Interrupt Service Routine in the Interrupt Vector Table → runs it (in kernel mode) → restores state → resumes. A higher-priority interrupt can interrupt an ISR (nested interrupts).
  • DMA (Direct Memory Access): a dedicated controller transfers data between device and memory without CPU involvement for each byte; the CPU sets it up and is interrupted only when the whole block is done. Used for high-throughput I/O (disks, NICs).

7. Security & Access Control

How does the OS prevent unauthorized access?

  • DAC (Discretionary Access Control): The owner of a file decides who can access it (e.g., standard Linux permissions like chmod 755).
  • MAC (Mandatory Access Control): The OS enforces security policy based on clearance levels (e.g., Top Secret vs. Public). Users cannot change these permissions.
  • RBAC (Role-Based Access Control): Permissions are assigned to “roles” (e.g., Admin, User, Guest), and users are assigned to those roles.
  • ACL (Access Control List): a per-object list of which users/groups may do what (read/write/execute) — finer-grained than classic mode bits.
  • Authentication vs. Authorization: authentication proves who you are (password, biometrics); authorization decides what you may do (permissions). AuthN first, then AuthZ.

8. Cheat Sheet — Algorithms Side-by-Side

CategoryAlgorithmKey property
SchedulingFCFSConvoy effect
SJF/SRTFOptimal avg waiting (SRTF preemptive)
Round RobinFair; quantum-dependent
PriorityStarvation (fix: aging)
MLQ/MLFQMultiple queues; MLFQ solves aging
ReplacementFIFOBelady’s anomaly
LRUStack algorithm, best practical
OptimalBenchmark only (needs oracle)
ClockLRU approx via reference bit
DiskFCFSSimple, poor seek
SCANElevator, no starvation
C-SCANUniform wait, one-direction

Expert-Level Questions

If you are asked these, you are aiming for high-level roles:

1. “How does the OS handle an interrupt?”

  • Answer: The CPU stops its current task, saves its state (registers/PC) to the stack, jumps to an Interrupt Service Routine (ISR) address (found in the Interrupt Vector Table), executes the code, and then restores the state to resume the original process.

2. “What is the difference between Synchronous and Asynchronous IPC?”

  • Answer: Synchronous (Blocking) requires both processes to be ready at the same time (like a phone call). Asynchronous (Non-blocking) allows a process to send a message and immediately continue (like sending an email).

3. “What is the Convoy Effect and how do we avoid it?”

  • Answer: It happens when a long-running process occupies the CPU in FCFS scheduling, causing short processes to wait. We avoid it by using Preemptive algorithms like Round Robin.

4. “What is priority inversion and how is it solved?”

  • Answer: A low-priority process holds a lock that a high-priority process needs, while a medium-priority process runs and starves the high one. Solved with priority inheritance (the lock holder temporarily runs at the waiter’s priority).

My Private Notes

Notes are auto-saved locally to this device.