Secondary Storage, I/O Systems, and OS Interview Questions
A comprehensive study guide covering file system architectures, secondary storage hierarchies, Input/Output management strategies (Polling, Interrupts, DMA, Spooling), cache memory hierarchies, Linux access permissions, virtualization concepts, and core Operating System interview questions.
1. File Systems: Structure, Operations, and File Access Methods
A file is a named collection of related information recorded on secondary storage (e.g., HDDs, SSDs). It represents programs (source and binary forms) and data (numeric, alphabetic, alphanumeric, or multimedia).
File Attributes
The operating system maintains metadata associated with each file:
- Name: Human-readable identifier.
- Type: Differentiates formats (
.pdf,.txt,.png,.bin,.sh). - Location: Pointer to the device and disk block location.
- Size: Current file size (in bytes, words, or blocks).
- Protection / Ownership: Access-control permissions and user identity.
- Timestamps: Creation, last modification, and last access metadata.
Basic File Operations
- Create / Open: Allocates space and links metadata to the active file table.
- Read / Write: Updates internal file offset pointers and transfers data buffers.
- Seek: Repositions the file offset pointer without modifying data.
- Delete / Truncate: Releases allocated storage blocks and cleans metadata.
File Access Methods
2. Directory Hierarchies and Disk Allocation Methods
Directories map human-readable file names to the corresponding directory entries containing file control blocks (FCBs).
Directory Structures
- Single-Level Directory: A single directory contains all files. Causes naming collisions and organization bottlenecks when scaled.
- Two-Level Directory: Each user gets a dedicated User File Directory (UFD) under a Master File Directory (MFD). Isolates users but lacks sub-folder nesting.
- Tree-Structured Directory: A multi-level hierarchical tree with a root directory. Enables path-based navigation (
/home/user/docs/report.pdf). Standard in Linux and Windows. - Acyclic-Graph Directory: Allows directories to share subdirectories and files via aliasing/links (e.g., hard and soft symlinks). Requires cycle-detection algorithms to avoid infinite traversal loops.
- General Graph Directory: Flexible graph structure. Requires reference counting or garbage collection to reclaim circular orphaned dependencies.
Disk Block Allocation Strategies
To store a file spanning multiple disk blocks, the OS uses one of three allocation strategies:
3. I/O Hardware Management and Data Transfer Mechanisms
The OS abstracts diverse physical hardware devices (keyboards, disks, network cards) into standardized I/O subsystems via device drivers.
1. Polling (Programmed I/O)
The CPU periodically loops and checks the busy-wait bit of the device status register until the device completes its operation.
- Advantage: Conceptually simple; minimal hardware dependencies.
- Disadvantage: Wastes significant CPU cycles in busy-wait loops.
2. Direct Memory Access (DMA)
Offloads bulk data transfers between I/O devices and main memory entirely from the CPU.
3. Buffering vs. Spooling
- Buffering: Uses a dedicated region of main memory to store data temporarily while it is transferred between two devices or between a device and an application. Compensates for speed mismatches and data-transfer size variations.
- Types: Single Buffer, Double Buffer (Ping-Pong buffering), Circular Buffer.
- Spooling (Simultaneous Peripheral Operations On-Line): Intercepts output jobs intended for slow, non-shareable sequential devices (such as physical printers) and writes them to a dedicated disk queue. The operating system dequeues these jobs sequentially while the producing applications proceed without blocking.
4. Disk Geometry and Scheduling Algorithms
A traditional magnetic hard disk drive (HDD) organizes data across multiple platters:
- Platters: Flat circular disks coated with magnetic material.
- Tracks: Concentric rings on each platter surface.
- Sectors: The smallest addressable unit on a track (typically 512 bytes or 4 KB).
- Cylinders: The set of all matching tracks across all vertical platters.
- Read/Write Head: An electromagnetic actuator hovering over spinning platters.
Seek Time (Arm Movement) + Rotational Latency (Platter Spin) + Transfer Time = Total I/O Time
Disk Scheduling Request Queue: [ 98, 183, 37, 122, 14, 124, 65, 67 ] (Current Head: 53)
- FCFS (First-Come, First-Served): Services requests in the order they arrive. Safe and fair, but yields long seek paths.
- SSTF (Shortest Seek Time First): Selects the pending request closest to the current head position. Minimizes overall head movement, but can cause starvation for distant requests.
- SCAN (Elevator Algorithm): The disk arm moves continuously in one direction servicing requests until it reaches the disk boundary, then reverses direction.
- C-SCAN (Circular SCAN): Moves in one direction servicing requests until reaching the end, then immediately resets to the beginning without servicing requests on the return trip. Provides uniform waiting times.
- LOOK / C-LOOK: Variants of SCAN/C-SCAN that reverse or reset as soon as the last request in the current direction is reached, rather than traveling to the physical disk edge.
5. Cache Memory Architecture and Performance Metrics
Cache memory is a small, ultra-fast volatile memory located directly on or adjacent to the CPU chip, bridging the latency gap between high-speed CPU registers and slower main memory (RAM).
Hit Ratio and Effective Access Time (EAT)
- Cache Hit: Requested data block is present in the cache.
- Cache Miss: Requested data is missing; must be fetched from lower memory levels.
- Where:
- = Cache Hit Ratio ()
- = Cache Miss Ratio
- = Cache access time
- = Main memory access penalty
6. Protection, Security, and Linux File Permissions
The OS isolates processes and users from unauthorized access to hardware and memory regions.
Linux File Permission Model (POSIX ACLs)
In Linux/Unix systems, file permissions are modeled in a 9-bit matrix spanning three identity domains: Owner (User), Group, and Others.
- Read (
r= 4): Permission to read file contents or list directory entries. - Write (
w= 2): Permission to modify file data or add/remove directory entries. - Execute (
x= 1): Permission to run the binary/script or traverse (cd) a directory.
# Example permission calculation:
# Owner: r w x = 4 + 2 + 1 = 7
# Group: r - x = 4 + 0 + 1 = 5
# Others: r - - = 4 + 0 + 0 = 4
chmod 754 application.sh
7. Virtualization vs. Containerization
8. Operating System Core Interview Review
High-Yield Technical Q&A
Q1: What is the exact sequence of an Interrupt handling lifecycle?
- An asynchronous hardware signal or software exception triggers the interrupt.
- The CPU finishes the current instruction and pushes the Program Counter (PC) and processor registers onto the kernel stack.
- The CPU looks up the Interrupt Service Routine (ISR) address in the Interrupt Vector Table (IVT).
- The kernel switches from User Mode to Kernel Mode and executes the ISR.
- Upon completion, the CPU executes an
IRETinstruction, restoring the saved registers and context, and resumes the original process in User Mode.
Q2: How does Kernel Mode differ from User Mode?
- User Mode (Ring 3): Applications execute with restricted CPU privileges. Direct access to physical memory, hardware devices, and privileged instructions (
cli,hlt) is blocked. - Kernel Mode (Ring 0): The OS kernel runs with unrestricted access to hardware instructions and physical memory addresses.
Q3: What is the difference between Polling and DMA?
- Polling requires the CPU to repeatedly check the status register of an I/O device in a loop, consuming CPU cycles that could otherwise run applications.
- Direct Memory Access (DMA) offloads data transfers: the CPU programs a DMA controller with source, destination, and transfer size, and the controller moves the data directly between memory and device without further CPU involvement.
Q4: Why are Indexed Allocations favored over Linked Allocations for large file access?
Linked allocation requires traversing blocks one by one (), making random seeks slow. Indexed allocation consolidates pointers into a dedicated index block, enabling random lookups to arbitrary block locations.
Summary and Key Takeaways
- Storage Hierarchies: File access patterns dictate disk design. Sequential models fit streams and logs, direct models fit random reads, and indexed models back database engines.
- Allocation Strategies: Contiguous allocation optimizes throughput but causes external fragmentation; linked allocation removes external fragmentation but hinders direct seeks; indexed allocation balances both via explicit pointer blocks.
- I/O Management: Polling uses busy-wait CPU polling; Direct Memory Access (DMA) frees the CPU by delegating bulk I/O transfers directly to RAM.
- Spooling: Solves contention on non-shareable devices (like printers) by queueing intermediate output jobs on disk.
- Disk Scheduling: Algorithms like SSTF, SCAN, and C-SCAN balance head travel distance against starvation risks.
- Memory Caching: Leverages temporal and spatial locality. The Effective Access Time depends on the hit ratio () across L1, L2, and L3 cache levels.
- Security & ACLs: The 9-bit Linux model (
rwx-rwx-rwx) establishes access boundaries across Owner, Group, and Others. - Virtualization vs. Containers: Hypervisor VMs virtualize complete hardware stacks with separate guest operating systems; containers share the host kernel via namespaces and cgroups for lower overhead.