BTI Beyond The Interviews

CS Fundamentals · 11 sections

Operating Systems

Processes, threads, memory, scheduling, sync, filesystem, I/O, IPC, and containers — the OS interview core.

Premium · preview 133 cards Updated 24 Oct 2026
Free to preview. The first 3 cards and the full outline are below — the rest of this sheet is part of the Cloud, DevOps & CS Fundamentals bundle.

What's inside

Preview — first 3 of 133 cards

User mode vs kernel mode

CPUs implement privilege levels (x86 rings 0-3; Linux uses ring 0 for the kernel, ring 3 for user code). Ring 0 may execute privileged instructions (cli/sti, writing cr3, in/out, MSRs) and address any physical frame; ring 3 faults on them. That split is what makes isolation real: a user bug becomes SIGSEGV, not a kernel crash. Every crossing is a hardware-mediated transition through the IDT, so the cost is the mode switch, not a normal call.

unsigned long x;
// ring 3: both of these raise #GP -> SIGSEGV
asm volatile("cli");                      // disable interrupts
asm volatile("mov %%cr3, %0" : "=r"(x));  // read page-table base

System call (how it works)

The controlled entry into the kernel. x86-64: syscall number in rax, arguments in rdi, rsi, rdx, r10, r8, r9; execute syscall; the CPU switches to ring 0, saves the return frame, and indexes sys_call_table. The result comes back in rax, where values in -4095..-1 mean -errno. glibc wrappers turn that into a -1 return plus errno. Everything from printf to malloc's brk/mmap ultimately crosses this boundary.

ssize_t n = write(1, "hi\n", 3);   // glibc wrapper for __NR_write
if (n < 0) perror("write");        // errno = EINTR / EFAULT / EPIPE

// what the wrapper does:
//   rax=1, rdi=1, rsi=buf, rdx=3;  syscall;  result in rax

System call cost and vDSO

Roughly 100-500 ns each: two privilege transitions, register save/restore, KPTI and Spectre mitigations, plus cache and branch-predictor pollution. That is why servers batch (readv/writev, sendmmsg, io_uring) instead of looping on tiny calls. The vDSO maps a few kernel-provided pages read-only into every process so clock_gettime, gettimeofday, time and getcpu run entirely in user space with no trap.

clock_gettime(CLOCK_MONOTONIC, &ts);   // vDSO path, no syscall

$ strace -c -f ./server      # per-syscall count and time
$ perf trace -s ./server

130 more cards in this sheet

Unlock the Cloud, DevOps & CS Fundamentals bundle — ₹399

One-time payment. Unlocks this sheet and 8 other sheets in the bundle, plus a typeset PDF of each.

Unlock the bundle See all bundles

Or get all 76 sheets for ₹999 — one payment, every future sheet included.