Systems study
Offline — showing the cached copy.
Home / Operating Systems / 1. Kernel, user mode and syscalls

1. Kernel, user mode and syscalls

One-liner. The CPU has privilege levels; the kernel is the only code allowed to change the machine.

Memorize

  • User mode cannot touch devices, page tables or other processes; kernel mode can.
  • A syscall is a controlled transition: trap instruction → saved registers → handler → return.
  • Cost: mode switch + register save/restore. Tens to hundreds of nanoseconds — cheap once, expensive in a loop.
  • Interrupts (hardware) preempt everything; exceptions are synchronous (fault, trap, abort).
  • The kernel is monolithic (Linux: all services in one address space) but modular (loadable modules LKMs).
  • Common abstractions: process, file descriptor, socket, inode, page, namespace.
  • strace shows the boundary: every line is one syscall.
SYSCALL PATH User code syscallinstruction mode switch kernel handler device/filelogic return user code
Syscall path

Trap. Believing write() is synchronous because it returned — it usually just copied into the page cache. Do this. Use fsync/fdatasync when durability matters, and measure it.

Check

Why is a syscall more expensive than a normal function call?