Skip to main content...
How Computers Work + OS Essentials
25 min

Day 2: Processes vs threads; kernel & system calls

The kernel: the kitchen manager

The kernel is the part of the operating system with privileged access to hardware. Ordinary programs ('user space') can't touch the disk or network card directly — they ask the kernel to do it on their behalf via a system call (open, read, write, socket, fork...). This boundary is what makes an OS an OS: a layer of controlled, arbitrated access to shared hardware.

Why the boundary exists

If any program could write directly to disk sectors or network hardware, one buggy or malicious program could corrupt the whole machine. The kernel/user-space split is the OS's original security boundary — everything in Phase 11 (Kubernetes Security) and Phase 26 builds on variations of this same idea.

Process vs thread

A process is a running program with its own private memory space — one process cannot casually read another's memory. A thread is a unit of execution *within* a process; all threads in a process share that process's memory. This is the core trade-off: processes are isolated but heavier (and communicating between them requires explicit mechanisms — pipes, sockets, shared memory); threads are lightweight and share memory for free, but that sharing is exactly what makes concurrency bugs possible.

  • Process: isolated memory, higher overhead to create, safer by default
  • Thread: shared memory within its process, cheap to create, requires explicit synchronization to be safe
  • A process always has at least one thread (the "main" thread)

Payoff, later

Node.js is single-threaded for your JS code but uses a background thread pool (libuv) for I/O — this is exactly why a CPU-heavy synchronous function blocks your entire event loop (Phase 23, performance engineering, is largely about finding exactly this kind of bug).

See processes and threads on a real Linux box (Phase 1 will make these tools second nature)
# List processes
ps aux | head

# Show thread count for a process (Linux)
ps -o nlwp <pid>

# Live view of processes
top

Key terms

Kernel
The privileged core of the OS that mediates all access to hardware.
System call (syscall)
A controlled request from a user-space program into the kernel, e.g. read(), write(), fork().
Process
A running program with its own isolated memory space.
Thread
A unit of execution within a process; threads in the same process share memory.

What is the main risk that comes with using threads instead of separate processes?

We use cookies

We use cookies to enhance your browsing experience, serve personalized content, and analyze our traffic. By clicking "Accept All", you consent to our use of cookies. Learn more

    Day 2: Processes vs threads; kernel & system calls | RBTechIconX