Interview Q&A / Operating Systems

INTERVIEW Q&A · 42 QUESTIONS

Operating Systems interview questions

Processes, threads, scheduling, memory and deadlocks, in plain words.

  1. What is virtual memory, and how does paging work?

    Virtual memory gives every process its own private address space that looks large and continuous, while the OS maps it onto real RAM in fixed-size blocks called pages (often 4 KB). A page table translates each virtual page to a physical frame, and pages not in RAM can be kept on disk and loaded on demand through a page fault.

    IntermediateIn-depth4 min read
  2. What is thrashing in an operating system, and how can it be prevented?

    Thrashing is when a system spends most of its time moving pages between RAM and disk instead of running programs, because the running processes together need more memory than is available. It is prevented by giving each process enough frames for its working set, controlling page-fault rate, and reducing the number of running processes.

    AdvancedIn-depth4 min read
  3. A system has 4 KB pages. Translate logical address 20000 if page 4 is stored in frame 9.

    20000 = 4 x 4096 + 3616, so page number 4 and offset 3616. Frame 9 starts at 9 x 4096 = 36864, so the physical address is 36864 + 3616 = 40480.

    BeginnerQuick answer1 min read
  4. What is the difference between paging and segmentation?

    Paging divides memory into fixed-size pages invisible to the programmer; segmentation divides it into variable-size logical units like code, stack and heap. Paging causes internal fragmentation, segmentation causes external.

    BeginnerQuick answer1 min read
  5. A system has 32-bit logical addresses and 4 KB pages. How many bits are the page number and offset, and how large is the page table?

    4 KB = 2^12, so the offset is 12 bits and the page number is 32 - 12 = 20 bits. That gives 2^20 entries; at 4 bytes each, the page table is 4 MB per process.

    IntermediateQuick answer1 min read
  6. If a TLB lookup takes 10 ns, memory access 100 ns and the hit ratio is 90%, what is the effective access time?

    EAT = 0.9 x (10 + 100) + 0.1 x (10 + 100 + 100) = 99 + 21 = 120 ns. A TLB hit needs one memory access; a miss needs two, one for the page table and one for the data.

    IntermediateQuick answer1 min read
  7. What does a page table entry contain besides the frame number?

    Besides the frame number, an entry holds control bits: valid/present, read/write/execute permissions, a user/supervisor bit, a dirty (modified) bit and an accessed (reference) bit.

    IntermediateQuick answer2 min read
  8. Why do operating systems use multi-level page tables?

    A single flat page table needs an entry for every possible page, even unused ones. A multi-level table splits it into pieces and only allocates the pieces for regions actually in use, saving a large amount of memory.

    IntermediateQuick answer1 min read