50 Linux & OS interview questions with detailed answers, sorted from basic to advanced. Free to practice, with progress saved automatically.
An operating system manages CPU time, memory, storage and devices on behalf of running programs, and Linux is the usual environment for backend and DevOps work. Questions cover processes and threads, CPU scheduling, virtual memory and page replacement, synchronization, race conditions, deadlocks, I/O multiplexing, kernel design, file descriptors and practical Linux usage.
and 4 more topics.
A process is an independent unit of execution with its own memory space (virtual address space, heap, stack, file descriptors). A thread is a lighter-weight unit of execution within a process: threads in the same process share the heap, code, and file descriptors but each…
A context switch is when the OS stops the thread running on a core so another can run: it saves the old thread's CPU state (registers, program counter, stack pointer) and loads the new thread's state. It happens when a time slice ends or when…
Process scheduling is how the OS picks which process gets the CPU next. Algorithms differ in whom they favor and whether they interrupt the running process. - FCFS: first come, first served. One long process at the front makes every short one behind it wait…
IPC refers to the mechanisms that allow independent processes to exchange data, since they do not share memory directly. - Pipe (anonymous pipe): a one-way data stream between a parent and child process. - Named pipe (FIFO): a pipe with a filesystem name that does…
A deadlock is when two or more threads (or processes, transactions) wait on each other in a cycle: each holds a resource the other needs, so none can proceed. Thread 1 locks a and waits for b, thread 2 locks b and waits for a:…
A mutex is a lock that lets only one thread into a critical section at a time, and the thread that locks it is the one that must unlock it (ownership). A semaphore is a counter: initialized to N, it lets at most N threads…
Concurrency is structuring a program so several tasks are in progress at once: when one waits, switch to another, even on a single CPU. Parallelism is several tasks actually running at the same instant on multiple cores. Rob Pike's summary: concurrency is about structure, parallelism…
A thread pool is a set of pre-created worker threads that are reused, instead of spawning and destroying a thread for each task. Creating a thread has a cost: each thread needs its own stack (the JVM default is about 1MB on Linux x64), the…
Virtual memory is a layer between a process and physical RAM. Each process sees its own contiguous address space. When the process reads an address, the MMU hardware looks up that process's page table to turn the virtual address into a real RAM address, in…
Both divide memory so virtual addresses can be translated to physical ones; they differ in block size: - Paging splits virtual memory into fixed-size pages (usually 4 KB) and RAM into frames of the same size; the page table records which page sits in which…
A memory leak is memory the program no longer needs but never releases, so usage keeps growing until the process is OOM-killed. Node.js and Go have a garbage collector (GC) that only reclaims objects nobody references anymore. So a leak in these languages is a…
A file system turns a disk (just a sequence of blocks) into a tree of named directories and files. It does three jobs: store each file's metadata (permissions, owner, timestamps, size, which blocks hold the data; on Linux this is the inode), track free blocks,…
A signal is an asynchronous notification the OS or another process sends to a process: SIGTERM (15, termination request — what kill PID sends by default), SIGKILL (9, forced kill — cannot be caught or ignored), SIGINT (2, Ctrl+C), SIGHUP (1, terminal closed / reload…
A race condition happens when a program's result depends on the order in which threads run, and nobody controls that order. The most common form is two threads reading and then writing a shared variable: one overwrites the other's result (a lost update). counter++ is…
A monitor is an object that bundles shared data with a lock and condition variables. The lock ensures only one thread runs inside at a time; a condition variable lets the lock holder release the lock and sleep while a condition is unmet, then be…
All four solve the same problem: one thread watches thousands of sockets and needs to know which ones have data so it can read without blocking. Each generation fixes what was expensive in the previous one. - select: on every call the app passes the…
MLFQ (Multilevel Feedback Queue) is a scheduler with several queues of different priority that infers which processes are interactive and which are CPU-heavy from how they use the CPU. CFS is Linux's scheduler since 2.6.23 (replacing the O(1) scheduler); it has no priority queues and…
These three concepts belong together because Linux treats almost every I/O source as a "file": - File descriptor (FD): an integer the kernel returns when a process opens a file, socket, pipe or device. The process reads and writes through that number instead of holding…
Linux processes have 5 main states: R (running), S (interruptible sleep), D (uninterruptible sleep), Z (zombie), T (stopped). A process briefly entering D while waiting on disk I/O is normal; only many processes stuck in D for a long time point to a storage problem.…
Copy-on-Write (CoW) is how fork() creates a child process without copying memory up front. After fork(), parent and child share the same physical memory pages, and the kernel marks those pages read-only on both sides. When either side writes to a page, the CPU raises…
An inode stores everything about a file except its name: permissions, owner, size, timestamps, link count, where the data blocks are. The name lives in the directory, which is a table mapping "name → inode number". ls -li shows a.txt and hard.txt with the same…
The page cache is free RAM that the Linux kernel uses to keep the contents of files that were recently read or written. The first read of a file goes to disk and the data stays in RAM; the next read is served straight from…
When physical memory is full and a new page must be loaded, the OS must evict a page: - FIFO: evicts the oldest-loaded page. Simple but ignores whether it is still heavily used. - LRU (Least Recently Used): evicts the page unused for the longest…
Thrashing is a state where the system spends most of its time swapping pages in and out of disk instead of executing instructions — CPU utilization drops while the disk stays busy. Cause: the combined memory demand (working set) of the running processes exceeds physical…
Demand paging: pages are loaded into RAM only when actually accessed, instead of loading the whole program at startup. Each page-table entry has a valid/invalid bit marking whether the page is in RAM or still on disk. When the CPU accesses a page whose bit…
A process’s life cycle: - New: being created, not yet in the ready queue. - Ready: able to run, waiting only for the scheduler to grant a CPU. - Running: executing on a CPU (only one process per core at a time). - Waiting (Blocked):…
Both concern how Unix manages the parent–child relationship. Zombie (defunct): a child has terminated (exit) but the parent has NOT yet called wait()/waitpid() to read its exit status. The child released most resources, but its process-table entry remains to hold the exit code → shown…
Both are wasted memory, but in different forms. Internal fragmentation: the unused leftover space INSIDE an allocated block. It happens with fixed-size allocation — e.g. you need 3KB but get a whole 4KB page → 1KB is wasted inside the page. Paging always has internal…
A logical (virtual) address is generated by the CPU/program; each process sees its own contiguous virtual address space starting at 0. A physical address is a real location in the RAM chips. The MMU (Memory Management Unit) is hardware that translates virtual → physical on…
The PCB is the OS data structure that represents and manages each process — a complete record that lets a process be paused and later resumed. Main fields: - Process state: new/ready/running/waiting/terminated. - PID: the process identifier (and usually the parent PID). - Program counter:…
Starvation (indefinite blocking): a process is delayed indefinitely and never gets the CPU. Common under priority scheduling: if higher-priority processes keep arriving, a low-priority one may wait forever. Aging: a technique that gradually raises a process’s priority based on how long it has waited. For…
The difference is whether the OS may take the CPU away from a running process. Non-preemptive (cooperative): once granted the CPU, a process keeps it until it voluntarily releases it — by terminating or moving to waiting (for I/O). The scheduler decides only at those…
Kernel-level threads: the kernel knows about and schedules each thread. Switching threads requires entering the kernel (costlier), but many threads run truly in parallel across cores, and one thread blocking on I/O does not block the whole process. User-level threads: managed by a userspace library;…
The difference is how much OS functionality runs in kernel space. Monolithic kernel: nearly all services — process and memory management, file system, drivers, network stack — run together in kernel space and call each other directly via function calls. - Pros: high performance (few…
Modern CPUs have at least two privilege levels, distinguished by a mode bit: - User mode: application code runs here and may NOT execute privileged instructions (direct hardware access, editing page tables, disabling interrupts, ...). - Kernel mode (supervisor): kernel code runs with full hardware…
Swapping: the OS moves pages (or, in older models, whole processes) from RAM to disk storage to free RAM, and loads them back when needed. This lets the combined address space of processes exceed physical RAM — the basis of virtual memory. Swap space: a…
RAID (Redundant Array of Independent Disks) combines multiple disks into one logical unit to improve performance and/or reliability, using two techniques: striping (splitting data across disks for parallel read/write) and mirroring/parity (redundancy for fault tolerance). - RAID 0 (striping): splits data across disks. Fast, full…
ls -la lists a directory in long format (-l) and includes hidden files (-a, all) — on Linux a hidden file is simply one whose name starts with a dot, like .env or .gitignore. Reading left to right: type (d directory, - file, l symlink)…
RAM is working memory: fast to read and write, but it loses its data when power is off (volatile). ROM keeps its data without power (non-volatile) and stores firmware — code that must be available the moment the machine powers on. RAM ROM --------- Power…
Compiled: the whole source is translated to machine code before running, producing an executable (C, C++, Go, Rust). Interpreted: another program (the interpreter) reads and executes the code at run time, with no separate machine-code file produced (shell scripts are the purest example). Compiled Interpreted…
The biggest difference is philosophy: Linux is an open-source kernel where everything is configured through text files and the command line; Windows is Microsoft's closed-source OS designed around a graphical interface and the Registry. Linux Windows --------- File system A single tree starting at /,…