Page 7: Operating System Abstractions: Processes, Threads, and System Calls

Understanding process isolation, thread contention, and blocking vs. non-blocking system calls is the key to building responsive web apps and scalable backend servers.

On a modern computer, dozens of applications run simultaneously—a web browser, a code editor, a database server, and background system services. If any program could read or overwrite arbitrary physical RAM addresses or access the network card directly, a single buggy or malicious script could crash the entire machine or steal sensitive credentials from another app.

The Operating System (OS) kernel prevents chaos by providing three foundational abstractions: Processes (isolated execution containers with their own virtual memory address space), Threads (independent execution streams scheduled onto CPU cores), and System Calls (controlled gates through which user programs request privileged hardware operations like reading files or opening network sockets).

7.1 Processes and Virtual Memory Isolation

A process is an instance of a running program. The OS assigns each process a unique Process ID (PID) and a private virtual address space. Thanks to the CPU’s Memory Management Unit (MMU), Process A cannot read or write the memory belonging to Process B unless explicit Inter-Process Communication (IPC) is configured.

In modern web browsers, each site tab runs inside its own sandboxed OS renderer process, ensuring that a crash or runaway loop in one tab does not freeze unrelated tabs.

7.2 Threads, Concurrency, and Race Conditions

Within a single process, multiple threads can execute concurrently. Every thread has its own independent Call Stack and CPU register state, but all threads within a process share the exact same Heap memory.

Sharing a Heap makes communication between threads fast, but it introduces a notorious hazard: race conditions. If two threads read, increment, and write the same shared counter simultaneously without synchronization, one thread’s update can overwrite the other’s. JavaScript avoids shared-memory race conditions by running your application code on a single main thread and using message passing (`postMessage`) for Web Workers.