OS and Computer Architecture Interview Questions

Short model answers to the questions asked most often.

Concept

Short model answers to the questions asked most often. Say the key idea first, then an example or a trade-off.

What is an operating system?

Software that manages hardware resources and provides abstractions (processes, virtual memory, files) and protection for programs (Module 8) Kernel mode vs user mode?

Privileged CPU mode for the kernel; restricted mode for applications; entered via system calls, exceptions and interrupts Process vs thread?

A process has its own address space; threads share their process's address space but have their own stacks and registers (Module 13) What happens on fork()?

The kernel duplicates the process; memory is shared copy-on-write; returns 0 in the child, the child's PID in the parent (Module 10) What is a zombie?

A terminated process whose parent hasn't called wait yet What is a context switch?

Saving one thread's CPU state and restoring another's; pure overhead, plus cache/TLB effects What is a system call?

A controlled entry into the kernel (syscall instruction) to request a service (Module 11) Interrupt vs exception?

Interrupts are asynchronous (devices, timers); exceptions are caused by the current instruction (faults, traps) (Module 12) Compare scheduling algorithms

FCFS (convoy effect), SJF/SRTF (optimal average wait, starvation), RR (response time), priority (aging against starvation) (Module 14) What is a race condition?

Outcome depends on timing of unsynchronized access to shared data (Module 15) Mutex vs semaphore?

A mutex is owned and provides mutual exclusion; a counting semaphore counts available resources and can be signalled by any thread Four conditions for deadlock?

Mutual exclusion, hold and wait, no preemption, circular wait; break one to prevent it (Module 16) Deadlock vs livelock vs starvation?

Blocked forever / active but no progress / one thread never gets service What is virtual memory?

Per-process address spaces mapped to physical memory by page tables and the MMU (Module 19) What is a page fault?

An access to a page that isn't mapped or permitted; the kernel maps it, loads it, copies it (COW) or sends SIGSEGV What is thrashing?

The working sets don't fit in RAM, so the system spends its time paging Paging vs segmentation?

Fixed-size pages (no external fragmentation) vs variable-size logical segments LRU vs FIFO vs OPT?

LRU approximates OPT well; FIFO is simple but suffers Belady's anomaly; OPT is the unattainable optimum (Module 20) Internal vs external fragmentation?

Waste inside allocated blocks vs free space split into unusable pieces (Module 21) What is an inode?

File metadata and block pointers, without the name (Module 22) Hard link vs symbolic link?

Another name for the same inode vs a file containing a path Polling vs interrupts vs DMA?

CPU checks repeatedly / device signals the CPU / device copies data to memory itself (Module 23) IPC mechanisms?

Pipes, FIFOs, message queues, shared memory, semaphores, signals, sockets (Module 17) What is an RTOS?

An OS with deterministic, priority-based scheduling for deadlines (automotive: AUTOSAR OS) Von Neumann vs Harvard?

Shared vs separate instruction and data memories; modern CPUs are von Neumann with split L1 caches (modified Harvard)

Simple fixed-length load/store instructions vs complex variable-length instructions with memory operands (Module 5) What is two's complement?

Signed representation where −x = ~x + 1; one adder serves signed and unsigned (Module 2) Carry vs overflow flag?

Unsigned vs signed overflow (Module 4) The instruction cycle: read instruction at PC, decode fields, execute, access memory, write back (Module 6) What is pipelining?

Overlapping instruction stages to raise throughput (Module 24) Types of hazards?

Structural, data (RAW; WAR/WAW with OoO), control What is forwarding?

Passing results between pipeline stages before write-back How does branch prediction work?

Predict outcome/target from history (2-bit counters, global history, BTB); flush on misprediction (Module 25) What is out-of-order execution?

Execute instructions when operands are ready, retire in order via the reorder buffer; register renaming removes false dependencies Explain the memory hierarchy

Registers, L1, L2, L3, DRAM, SSD: faster/smaller at the top; works because of locality (Module 18) Direct-mapped vs set-associative?

One possible location per line vs N locations in a set; associativity reduces conflict misses What is a TLB?

A cache of virtual-to-physical translations What is cache coherence / MESI?

Keeping per-core caches consistent; line states Modified, Exclusive, Shared, Invalid (Module 26) What is false sharing?

Independent variables in one cache line causing coherence traffic What is a memory barrier?

An instruction that enforces ordering of memory operations Byte order of multi-byte values; x86 little-endian, network byte order big-endian What is Amdahl's law?

Speedup is limited by the serial fraction: 1 / ((1 − f) + f / s) What limits clock frequency?

The critical path delay and power density "What Happens When…" Questions

…you run ./a.out? The shell forks; the child calls execve; the kernel maps the ELF segments and the dynamic linker; the linker loads libraries and relocates; startup code calls main (Modules 9–10).

…you call printf? Formatting into the stdio buffer, a write system call when flushed, the mode switch, the kernel's file object, the device (Module 30).

…a program accesses an array element? Address calculation, TLB lookup, cache lookups L1→L2→L3→DRAM, possibly a page fault (Modules 18–19).

…you press a key? Device interrupt, driver, input subsystem, terminal/window system, the waiting process becomes ready and is scheduled (Modules 12, 14, 23).

Why It Matters

Operating systems and computer architecture are core subjects in university exams, GATE-style tests and interviews for systems, embedded, automotive, backend and performance roles.

Syntax

Answer pattern: definition → mechanism → example → trade-off. For numerical questions (scheduling, page replacement, cache bits, disk scheduling), show a table or diagram of the steps.

Example

Each answer above points to the module where the topic is demonstrated with a real program; running those examples is the best preparation because you can describe what you *observed*.

Expected Result

You should be able to answer every question in the tables in two or three sentences and back it up with an example from the course.

Common Mistakes

Reciting definitions without a mechanism ("the OS manages resources").

Confusing similar pairs: process/thread, mutex/semaphore, coherence/consistency, paging/segmentation, internal/external fragmentation.

Guessing numerical answers instead of drawing the Gantt chart or frame table.

Best Practices

Practise numerical problems on paper: scheduling, page replacement, Banker's algorithm, cache address splitting, disk scheduling.

Keep one real story per topic ("I measured false sharing…").

For design questions, name trade-offs explicitly.

Practice Questions

Explain copy-on-write in under a minute.

Draw the pipeline diagram for a load followed by a dependent add, with and without forwarding.

Explain why sorting data can speed up a loop with an if.

Describe what happens from pressing Enter on ls to seeing the output.

Quick Quiz

Q1. (Multiple choice) Which is NOT one of the four deadlock conditions? A) Mutual exclusion B) Hold and wait C) Preemption D) Circular wait

Answer: C — the condition is *no* preemption.

Q2. (True/False) A TLB miss always causes a page fault.

Answer: False. A TLB miss triggers a page-table walk; a page fault happens only if the page isn't mapped or the access isn't allowed.

Q3. (Predict the output) How many times is "hi" printed by fork(); fork(); printf("hi\n");?

Answer: 4 (each fork doubles the processes).

Q4. (Find the bug) "Semaphores and mutexes are identical because a binary semaphore behaves like a lock."

Answer: A mutex has an owner (only the locker may unlock; enables priority inheritance and error checking); a semaphore has no owner and is used for signalling and counting.

Coding Challenge

Write a program that verifies the answer to Q3: fork twice, have every process print its PID after the forks, and let the original process wait until all descendants have finished so the output count can be checked.

#include <stdio.h>
#include <unistd.h>
#include <sys/wait.h>

int main(void)
{
    fflush(stdout);
    fork();
    fork();
    printf("hi from pid %d\n", getpid());
    fflush(stdout);
    while (wait(NULL) > 0) ;          /* each process waits for its own children */
    return 0;
}