Highlights

Contents

Back matter

Interview question bank

Explain what the mechanism protects, how it works, and where it can fail. Use the running example rather than reciting a definition.

Q1. What does the kernel protect?

It mediates access to execution, memory, files, devices, and privilege. User code requests permitted operations through controlled entry rather than directly controlling every shared resource.

Q2. How do a process and its executable differ?

The executable describes a program. A process is a running identity with execution state and resources. Exec can replace its program image without creating a new process identity.

Q3. Why does a context switch cost more than saving registers?

Switching can affect address-translation and cache behavior as well as scheduler bookkeeping. Useful work may need to rebuild locality afterward; a register-copy count is not total latency.

Q4. Why are concurrency and parallelism different?

Tasks can overlap through interleaving on one core. Parallelism requires simultaneous execution resources. Either interleaving or simultaneous execution can expose a shared-state race.

Q5. Why can a condition variable wake without the condition being true?

Wakeup tells a waiter to recheck, not that the predicate is guaranteed. Another thread may change shared state before the waiter reacquires the mutex, so wait in a predicate loop.

Q6. How can lock ordering prevent deadlock?

Every path acquires related locks in one consistent order, removing circular wait. A single reverse-order callback breaks that argument; a timeout only reacts to waiting afterward.

Q7. Why separate virtual addresses from physical frames?

The kernel can isolate, share, move, and protect memory while each process uses its own address space. Translation and its TLB cache connect that view to physical storage.

Q8. What does a page fault mean?

The access needs kernel handling because the current mapping or permission is insufficient. It can be a valid demand-loading event or an invalid access; not every fault means the machine ran out of RAM.

Q9. Why does fork not always copy all memory immediately?

Copy-on-write can share pages until a process writes. The kernel then provides private writable storage as required. The first write can therefore incur work postponed at fork.

Q10. What is a file descriptor?

A process-local handle to an open kernel-managed object. Files, sockets, and pipes share this interface but have different underlying behavior. Reusing an integer does not reuse the old connection identity.

Q11. Why does epoll not create parallel execution?

It reports ready descriptors. One event loop can handle them sequentially, while actual parallel work requires schedulable threads or processes and appropriate ownership.

Q12. How do containers differ from virtual machines?

Containers isolate selected views and resource policies while sharing a kernel. Virtual machines provide guest execution through virtualized hardware. Neither label alone specifies every security or resource guarantee.

Back matter

Exercises

One filled dot is a short explanation, two require diagnosis, and three require a complete design. Draw the mechanism before checking the solution.

E1 ●○○ The college admissions server has many idle connections. Why does one thread per connection not automatically help?

E2 ●○○ Two canteen-counter threads both read the same stock count, then write a decrement. Explain the lost update.

E3 ●●○ A child writes to a shared page after fork. Explain the next state.

E4 ●●○ An epoll callback performs a slow database query synchronously. Why can unrelated students experience delay?

E5 ●●● Design a server path from a launcher to a completed request.

E6 ●●● Diagnose a container that stalls despite apparently idle host cores.

Back matter

Worked solutions

Check the reasoning and its assumptions, not only the conclusion.

E1. Idle threads still need resources and coordination. Readiness-based waiting can identify the sockets with work without dedicating a blocked thread to each. CPU-heavy work needs a separate bounded execution policy.

E2. Both derive their replacement from the old value, so one write overwrites the other’s effect. Protect the read-modify-write as one critical operation rather than locking only the final store.

E3. Under copy-on-write, the mapping initially shares the physical page without permitting an unhandled private write. The fault handler establishes a private copy when necessary and updates the child’s mapping. The parent retains its own permitted view.

E4. The event loop cannot process their ready sockets while the callback blocks its execution context. Use a nonblocking path or bounded worker offload, and preserve result ownership and backpressure.

E5. Create the child, exec the server image, and reap its lifecycle correctly. Establish listeners and track accepted descriptors with bounded buffers. Wait for readiness, schedule bounded work, and access files through virtual-memory and filesystem mechanisms. Apply permissions and resource limits, then close owned resources on completion or failure.

E6. Inspect the group’s CPU quota and throttling counters, then distinguish runnable work from I/O waits or lock contention. Quota accounts aggregate scheduled CPU time, so several workers can exhaust it quickly. Namespaces change views; they do not grant additional CPU capacity.