Operating Systems Interview Questions

Fundamentals

Process vs Thread

Process: independent memory space; threads: lightweight units within a process sharing memory. Threads enable concurrency; processes provide isolation.

Scheduling

CPU scheduling

Algorithms: FCFS, SJF, Priority, Round-Robin. Goals: fairness, throughput, low latency. Modern OS use multi-level feedback queues.

Concurrency

Deadlocks and avoidance

Deadlock requires mutual exclusion, hold-and-wait, no preemption, circular wait. Avoid via ordering locks, timeouts, lock hierarchies.

Memory

Virtual memory and paging

Virtual addresses mapped to physical via page tables/TLB. Paging loads only needed pages; reduces memory footprint, enables isolation.

Storage

File systems and journaling

Common FS: ext4, NTFS, APFS. Journaling writes intent before data to ensure consistency after crashes. Concepts: inodes, directories, blocks.

I/O

Blocking vs Non-blocking I/O

Blocking waits for completion; non-blocking returns immediately. Async I/O uses event loops and callbacks to handle readiness.

Security

OS security primitives

Users/groups, permissions (ACLs), capabilities, sandboxing, SELinux/AppArmor, ASLR, process isolation.

Scheduling

Context switching

Saving/restoring CPU registers, program counter, and memory mappings to switch between processes/threads; contributes to overhead.

Kernel

System calls

User-space requests services via syscalls (open, read, write, fork). Interfaces differ across OS; use libc wrappers.

Concurrency

Mutex vs Semaphore

Mutex enforces mutual exclusion; semaphore controls access to resources with counters. Avoid deadlocks with ordering/timeouts.

Memory

Copy-on-write

Forked processes share pages as read-only until a write occurs, then copy is made; improves performance and memory usage.

Kernel

Kernel vs User mode

Kernel mode has unrestricted access; user mode is restricted. Transitions occur via traps/interrupts and syscalls.

Processes

CPU scheduling algorithms

Compare FCFS, SJF, Priority, Round Robin; trade-offs in throughput, fairness, and response time.

Concurrency

Deadlocks and prevention

Four conditions: mutual exclusion, hold-and-wait, no preemption, circular wait. Prevent via ordering, timeouts, detection and recovery.

Memory

Paging vs segmentation

Paging divides memory into fixed-size pages; segmentation uses variable-size logical units. Many systems combine both.

Storage

Filesystem journaling

Journaling (ext4, NTFS) logs metadata/data changes to recover after crashes; trade-offs in performance vs reliability.