10 Most Frequent OS Interview Questions: Processes, Memory, and File Systems Complete Coverage

Interview TopicsAuthor: BeautyResume Team

Covers 10 high-frequency OS interview questions on processes, memory, and file systems, each with exam focus and answer direction to help you fully prepare for operating system interviews.

Background

I learned operating systems poorly in college — just memorized process state transition diagrams for exams. After starting work, I found that interviewers ask very practical OS questions — why epoll is efficient, how virtual memory works, what's the real difference between processes and threads. I spent about ten days reorganizing high-frequency OS questions and found there are really just a few core knowledge points. Once you understand the underlying logic, you can apply it broadly in interviews. These 10 questions are the most frequently encountered across several companies I interviewed with.

I. Processes (3 Questions)

1. Differences Between Process, Thread, and Coroutine?

Exam Focus: Concurrency model understanding

A process is the basic unit of resource allocation with its own address space; a thread is the basic unit of CPU scheduling that shares the process's address space; a coroutine is a user-space lightweight thread scheduled by the program itself without kernel involvement. Key differences: process switching has the highest overhead (needs to switch page tables, TLB, etc.), thread switching is next (shared address space, only need to switch registers and stack), coroutine switching has the lowest overhead (only saves/restores registers in user space). Follow-up: When to use multi-process vs multi-thread? Multi-process suits CPU-intensive scenarios needing isolation (like Chrome's multi-process architecture); multi-thread suits scenarios needing shared memory. Go's goroutine is essentially a combination of coroutines + multi-thread scheduler.

2. Inter-Process Communication (IPC) Methods?

Exam Focus: Process collaboration mechanisms

Seven methods: Pipe (half-duplex, between parent-child processes), Named Pipe (between unrelated processes), Message Queue (message linked list in kernel), Shared Memory (fastest, needs semaphore for synchronization), Semaphore (counter for access ordering), Signal (asynchronous notification), Socket (cross-network communication). Interviewers love asking: Which is fastest? Shared memory, because it doesn't need data copying between kernel and user space. But shared memory requires manual synchronization, typically used with semaphores. In practice, same-machine uses shared memory + semaphores; cross-machine uses Socket or RPC.

3. Deadlock Conditions and Prevention?

Exam Focus: Deadlock theory

Four necessary conditions: Mutual Exclusion (resource can only be used by one process at a time), Hold and Wait (holding resources while waiting for others), No Preemption (acquired resources can't be forcibly taken), Circular Wait (processes form a circular waiting chain). Breaking any condition prevents deadlock: Mutual exclusion generally can't be broken; Hold and Wait can be addressed by requiring processes to request all resources at once; No Preemption can use timeout-based release; Circular Wait can be addressed by numbering resources and requesting in order. Follow-up: How to avoid deadlock in practice? The most practical methods are unified locking order and timeout settings. I use tryLock with timeouts in my projects to avoid deadlocks.

II. Memory (3 Questions)

4. What is Virtual Memory?

Exam Focus: Core memory management concept

Virtual memory provides each process with an independent, contiguous virtual address space mapped to physical memory through page tables. Core benefits: process isolation (each process has independent address space); memory protection (page table entries have permission bits); on-demand allocation (physical memory only allocated for actually accessed pages); memory overcommitment (pages can be swapped to disk when physical memory is insufficient). Follow-up: Virtual-to-physical address translation process? Virtual address → MMU checks TLB → TLB hit gives physical address directly → TLB miss checks page table → Page table hit gives physical address → Page table miss triggers page fault → Load page from disk to physical memory → Update page table and TLB.

5. Page Replacement Algorithms?

Exam Focus: Page fault handling strategies

Common algorithms: OPT (optimal, replaces page unused for longest time in future — theoretical, not implementable), FIFO (first in first out, may have Belady's anomaly — more physical pages cause more page faults), LRU (least recently used, good performance but high implementation overhead), Clock (approximate LRU using reference bits + circular linked list), LFU (least frequently used, evicts by frequency). Linux actually uses a modified Clock algorithm considering access and dirty bits. Follow-up: How to implement LRU? Hash table + doubly linked list, O(1) lookup and adjustment. This is the classic LeetCode 146 problem, often asked to code in interviews.

6. What is Memory Mapping (mmap)?

Exam Focus: File mapping mechanism

mmap maps a file into a process's virtual address space — reading and writing this memory is equivalent to reading and writing the file, with the OS responsible for syncing to disk. Advantages: avoids data copying between user and kernel space (traditional read/write needs two copies); suitable for large file processing; multiple processes mapping the same file enables shared memory. Disadvantages: mapping size limited by virtual address space; random write efficiency less than sequential write. Follow-up: Difference between mmap and read/write? read/write needs kernel buffer as intermediary; mmap operates directly on page cache. Kafka uses mmap to improve write performance.

III. File Systems (2 Questions)

7. What is an inode?

Exam Focus: File system metadata

An inode (index node) stores file metadata: file size, permissions, owner, timestamps, data block locations, etc. Key point: inodes don't store filenames — filenames are stored in directory entries (dentry). The number of inodes per partition is determined at formatting time. If there are many small files, inodes may be exhausted while disk space remains. Follow-up: How to check inode usage? df -i. How to resolve inode exhaustion? Delete unused files, reformat with more inodes, or use a larger disk.

8. Differences Between Soft Links and Hard Links?

Exam Focus: File linking mechanism

Hard link: different filenames pointing to the same inode; deleting one doesn't affect the other; cannot cross file systems; cannot link directories. Soft link (symbolic link): an independent file whose content is the path to another file; can cross file systems; can link directories; becomes invalid (dangling link) if the source file is deleted. Follow-up: ls -i shows hard links have the same inode number. Create hard links with ln, soft links with ln -s. In practice, soft links are used more often — for example, Nginx's sites-enabled directory uses soft links to manage configurations.

IV. Others (2 Questions)

9. Differences Between select, poll, and epoll?

Exam Focus: IO multiplexing mechanisms

select: monitors up to 1024 fds (FD_SETSIZE), copies fd set from user to kernel space on each call, requires traversing all fds to find ready ones after return, O(n) complexity. poll: no 1024 limit, uses linked list instead of bitmap, but still O(n) traversal. epoll: event-driven, epoll_ctl registers fds with kernel callbacks, epoll_wait only returns ready fds, O(1) complexity (actually O(number of active fds)); supports ET (edge-triggered, notifies once) and LT (level-triggered, continues notifying) modes. Follow-up: How to choose ET vs LT? ET is more efficient but harder to program (must use non-blocking IO + loop read until EAGAIN); LT is safer. Nginx uses ET, Redis uses LT.

10. Differences Between User Mode and Kernel Mode?

Exam Focus: Operating system privilege levels

Kernel mode runs OS kernel code with access to all memory and hardware; user mode runs applications with restricted memory access and no direct hardware operations. User-to-kernel mode transitions: system calls (voluntary), exceptions (like page faults), device interrupts (like keyboard input). Switching overhead: save/restore user-mode registers, switch stacks, update CPU privilege level, possible TLB and CPU pipeline flushes. Follow-up: How to reduce kernel mode switches? Use mmap instead of read/write, batch system calls, use vDSO (kernel-mapped read-only pages in user space where some system calls don't require switching).

Key Takeaways

For OS interview preparation, my experience: processes and memory are the absolute priorities, appearing in almost every interview; epoll is a must-know for backend developers — you must be able to explain the evolution from select/poll to epoll and its principles; virtual memory and page replacement are foundational for understanding memory management, best understood in the context of Linux's actual implementation. Also, OS questions are often combined with specific scenarios, like "why Redis uses single-threading" or "why Kafka uses mmap" — understanding OS principles is essential for answering these comprehensive questions.

FAQ

Q: Do I need to read Linux source code for OS interviews?
No need to read it all, but understanding key module implementations (like epoll source code, process scheduler) is a big plus.

Q: How to prepare for epoll interviews?
Focus on understanding ET/LT differences, epoll's data structures (red-black tree + ready list), and why it's more efficient than select/poll.

Q: What's commonly tested about processes and threads?
Differences and selection, IPC methods, thread synchronization mechanisms (mutex/condition variable/read-write lock), deadlock prevention and detection.

#操作 System#Linux#Big Tech Interview#Processes#Memory Management#Interview Trivia