OS Kernel and User Space
What you'll learn: You'll understand why modern operating systems strictly separate privileged kernel mode from restricted user mode.
Two Execution Environments
When your CPU runs code, it operates in one of two distinct modes: kernel mode or user mode. This separation is enforced by the processor's hardware, not just software convention.
Kernel mode (also called supervisor mode or privileged mode) grants unrestricted access to all system resources. Code running in kernel mode can:
- Execute any CPU instruction, including special privileged instructions
- Access all memory addresses directly
- Interact with hardware devices
- Modify processor control registers
User mode is a restricted execution environment where most application programs run. In user mode, the CPU:
- Blocks certain instructions from executing
- Restricts memory access to designated regions only
- Prevents direct hardware manipulation
- Triggers exceptions if code tries to exceed its authority
Why This Separation Matters
Think of it like a high-security building: kernel mode is the master key held by maintenance staff (the OS kernel), granting access to every room, the electrical panel, and fire systems. User mode is the standard employee badge—you can access your office and common areas, but trying to enter the server room triggers an alarm.
When a user program needs something privileged (like reading a file or allocating memory), it makes a system call—a controlled request that switches the CPU temporarily into kernel mode so the OS can safely perform the operation on the program's behalf.
This architecture prevents buggy or malicious applications from crashing the entire system, corrupting other programs' memory, or damaging hardware.
Key Takeaway: The kernel/user mode distinction creates a security boundary where the OS kernel runs with full privileges in kernel mode, while applications run with restricted access in user mode, requesting services through controlled system calls.