What is a Process?
A process is a running instance of a program together with all the state the operating system needs to manage it. While a program is a passive file on disk (an executable binary), a process is the active entity that the OS schedules on a CPU core, allocates memory for, and tracks through its lifetime.
Address Space Layout
Every process gets its own virtual address space, divided into well-defined segments:
| Segment | Contents | Growth direction |
|---|---|---|
| Text (code) | Machine instructions of the program | Fixed size |
| Data | Initialized global and static variables | Fixed size |
| BSS | Uninitialized globals (zero-filled on start) | Fixed size |
| Heap | Dynamically allocated memory (malloc, new) | Grows upward |
| Stack | Function call frames, local variables, return addresses | Grows downward |
The heap and stack grow toward each other. If they collide, the process runs out of memory.
Process States
A process transitions through a set of states during its lifetime:
- New -- the process is being created (binary loaded, PCB allocated).
- Ready -- the process is loaded into memory and waiting for the CPU scheduler to pick it.
- Running -- the process is actively executing instructions on a CPU core.
- Blocked (Waiting) -- the process cannot proceed because it is waiting for an event (disk I/O completion, network packet arrival, a lock release).
- Terminated -- the process has finished execution or was killed; its resources are being reclaimed.
State Transitions
The key transitions are: the scheduler moves a process from ready to running (dispatch). A timer interrupt can preempt a running process back to ready. When a process issues a blocking syscall (e.g., read()), it moves from running to blocked. When the awaited event completes, the process moves from blocked back to ready -- never directly to running.
Process Creation
On Unix/Linux, a new process is created with the fork() system call, which duplicates the calling process. On Windows, CreateProcess() creates a new process from scratch with a specified executable. In both cases, every process except the very first (PID 0 or 1) has a parent process, forming a tree hierarchy.
Real-Life: Running a Web Browser
When you double-click a browser icon, the OS performs the following steps:
- Creates a new process -- allocates a PCB, assigns a PID, sets state to New.
- Loads the executable -- reads the browser binary from disk, maps its text and data segments into virtual memory.
- Initializes the stack and heap -- the stack gets a default size (e.g., 8 MB on Linux), the heap starts small.
- Moves to Ready -- the process is placed on the scheduler's ready queue.
- Dispatched to Running -- when the scheduler picks it, the CPU begins executing the browser's
main()function.
Modern browsers use multiple processes:
- Chrome spawns a separate process for each tab. If one tab crashes, others survive. Each tab process has its own address space -- text, data, heap, stack -- completely isolated from other tabs.
- The browser's main process (the "browser process") handles the UI, while "renderer processes" handle web page content and "GPU processes" handle graphics.
- This multi-process architecture is a direct application of process isolation: one faulty renderer cannot corrupt the browser process or other tabs.
State transitions in action: When a tab makes a network request, its renderer process transitions from Running to Blocked. When the response arrives (signaled via an interrupt), the OS moves it back to Ready. The scheduler eventually dispatches it to Running again to process the response.