A topic in the Open Knowledge Graph — a free, open map of 15,290 topics and the order to learn them in.

System Calls and User/Kernel Mode

College Depth 92 in the knowledge graph ☐ I know this ☆ Set as goal
117topics build on this
353prerequisites beneath it
See this on the map →
Instruction Set Architecture (ISA)Kernel Mode and Privilege Levels+1 more→→Asynchronous I/O (AIO) OperationsException Handling: OS Internals+7 more
system-call user-mode kernel-mode trap privilege

Core Idea

CPUs operate in at least two privilege levels: user mode (restricted) and kernel mode (unrestricted). A system call is the controlled mechanism by which user-space programs request privileged services from the kernel, such as reading a file, spawning a process, or allocating memory. The call triggers a software interrupt or trap instruction that switches the CPU into kernel mode, executes the requested service, and returns control to user mode. The POSIX API (read, write, fork, exec, etc.) defines the standard system call interface on Unix-like systems.

How It's Best Learned

Use strace on Linux to observe which system calls a program makes. Then inspect how a simple write() call propagates from C library through libc wrapper, into the kernel, and back.

Common Misconceptions

Explainer

From your study of instruction set architecture, you know that the CPU executes instructions one after another, and that different instructions have different privileges. The key insight behind system calls is that modern CPUs enforce a protection boundary between two (or more) privilege levels. In user mode, programs can execute normal arithmetic and logic but cannot directly access hardware, modify page tables, or touch another process's memory. In kernel mode, the operating system has unrestricted access to everything. This separation exists to prevent a buggy or malicious program from crashing the entire system — if your web browser could directly write to disk sectors, a single bug could corrupt your filesystem.

But user programs still need to do things that require privilege: reading files, sending network packets, creating new processes. The system call is the controlled gateway between these two worlds. When your program calls `read()` to get data from a file, it doesn't directly access the disk. Instead, the C library places the system call number and arguments into specific CPU registers and executes a special trap instruction (like `syscall` on x86-64 or `svc` on ARM). This instruction simultaneously switches the CPU into kernel mode and jumps to a predefined entry point in the kernel. The kernel examines the request, validates the arguments, performs the privileged operation, places the result in a register, and switches back to user mode. Your program resumes as if it just returned from a normal function call.

The distinction between library functions and system calls trips up many beginners. When you call `printf("hello")` in C, you're calling a library function that formats your string, buffers it, and eventually calls the `write()` system call to actually send bytes to the terminal. The library function runs entirely in user mode; only `write()` crosses into the kernel. You can observe this directly using tools like strace on Linux, which intercepts and logs every system call a program makes. Running `strace ls` reveals dozens of calls — `openat()`, `read()`, `write()`, `close()` — showing that even a simple directory listing involves a rich conversation between user space and kernel space.

System calls are significantly more expensive than ordinary function calls. A regular function call might take a few nanoseconds — push arguments, jump, return. A system call involves saving all user-mode register state, switching privilege levels, potentially flushing CPU pipeline and cache state, executing the kernel code, then reversing the entire process. This overhead is why well-designed programs minimize system calls — buffering many small writes into one large `write()` call, for instance, or using memory-mapped files to avoid repeated `read()` calls. The POSIX standard defines the common system call interface (`read`, `write`, `fork`, `exec`, `open`, `close`, `mmap`, etc.) that Unix-like systems implement, giving programmers a portable vocabulary for requesting kernel services.

Practice Questions 5 questions

Prerequisite Chain

Understanding Zero → The Number Zero → Counting to Five → Counting to 10 → Counting to 20 → Counting a Set of Objects Up to 20 → Cardinality: The Last Number Counted → Matching Numerals to Quantities → Subitizing Small Quantities → Addition Within 10 → Number Bonds to 10 → Addition Within 20 → Doubles and Near Doubles → Doubles Facts Within 10 → Near Doubles Facts Within 20 → Mental Math Strategies for Addition → Mental Math: Adding and Subtracting Tens → Addition Within 100 → Repeated Addition as Multiplication → Multiplication as Equal Groups → Multiplication: Arrays → Basic Multiplication Facts (0s, 1s, 2s, 5s, 10s) → Multiplication Facts Within 100 → Division as Equal Sharing → Division as Grouping (Measurement Division) → Division: Grouping (Repeated Subtraction) Model → Division: Fair Sharing Model → Division as Equal Sharing → Division as Grouping → Basic Division Facts → Division Facts Within 100 → Multiplication and Division Fact Families → Relationship Between Multiplication and Division → Division Facts as Inverse of Multiplication → Remainders and Quotients in Division → Division Word Problems → Multi-Step Word Problems → Solving Multi-Step Word Problems → Multiplication Word Problems → Division Word Problems → Introduction to Long Division → Factors and Multiples → Prime and Composite Numbers → Equivalent Fractions → Relating Fractions and Decimals → Decimal Place Value → Integers and the Number Line → Comparing and Ordering Integers → Absolute Value → Adding Integers → Subtracting Integers → Multiplying Integers → Introduction to Exponents → Order of Operations → Integer Order of Operations → Variable Expressions → The Distributive Property → Variables and Expressions Review → Introduction to Polynomials → Adding and Subtracting Polynomials → Multiplying Polynomials → Factorial → Permutations → Combinations → Counting Principles: Addition and Multiplication Rules → Introduction to Graph Theory → Propositional Logic Foundations → Logical Equivalences → Boolean Algebra → Boolean Type and Truth Values → Comparison Operators and Boolean Tests → Logical Operators and Boolean Algebra → Boolean Algebra and Fundamental Laws → Logic Gates Fundamentals → Implementing Boolean Functions with Gates → Karnaugh Map Simplification → Combinational Circuit Design → Flip-Flops and Latches → Binary Counters: Design and Analysis → Binary Arithmetic → Fixed-Point Number Representation → Two's Complement Representation → Overflow and Underflow Detection → Binary Adders: Half-Adders and Full-Adders → Full Adder and Carry Propagation → Carry Lookahead Adder Design → Half Adder Circuit Design → Multiplication Circuit Design → Sequential Circuit Design → Registers and Register Files → Instruction Set Architecture (ISA) → Kernel Architecture and OS Structure → System Calls and User/Kernel Mode

Longest path: 93 steps · 353 total prerequisite topics

Prerequisites (3)

Leads To (9)