Quick Summary: A Process is an executing instance of a computer program that has its own isolated virtual address space, memory pages, file descriptors, and security context. A Thread (often termed a lightweight process) is the smallest dispatchable unit of CPU execution residing inside a process, sharing its parent's code segment, data, and heap while maintaining its own private stack and registers.
In modern operating systems (Linux, Windows, macOS), multitasking and concurrency are handled through processes and threads. Understanding the distinction between process boundaries and thread concurrency is essential for operating system exams, high-performance systems engineering, and multi-core programming.
FEATURE |
PROCESS |
THREAD |
|---|---|---|
Definition & Nature |
Heavyweight independent program in execution with private dedicated system resources. |
Lightweight unit of execution within a parent process sharing common resources. |
Memory Address Space |
Each process has an entirely isolated, private virtual address space protected by hardware MMU. |
All threads belonging to the same process share the identical address space, heap, and static data. |
Context Switching Speed |
Slow & Expensive: Requires flushing the CPU Translation Lookaside Buffer (TLB), switching page tables, and invalidating caches. |
Fast & Cheap: No page table change or TLB flush needed; only CPU registers, program counter, and stack pointer are swapped. |
Creation & Termination Overhead |
High overhead: allocating Process Control Block (PCB), page tables, and file descriptors via |
Minimal overhead: simply allocates a Thread Control Block (TCB) and small private stack via |
Communication Mechanism |
Requires formal Inter-Process Communication (IPC): Pipes, UNIX Domain Sockets, Message Queues, or shared memory segments. |
Direct memory access: threads communicate instantly by reading/writing shared global heap variables (requires mutex locks). |
Fault Tolerance & Stability |
High Isolation: If one process crashes or encounters a segmentation fault, neighboring processes continue running unaffected. |
Shared Vulnerability: If one thread crashes due to an illegal memory access or bad pointer, the entire parent process terminates. |
Operating System Data Structure |
Tracked by the OS kernel using a Process Control Block (PCB). |
Tracked by the OS scheduler using a Thread Control Block (TCB). |
fork()#include <stdio.h>
#include <unistd.h>
int main() {
pid_t pid = fork(); // Clones address space into parent & child process
if (pid == 0) {
printf("Child Process ID: %d\n", getpid());
} else {
printf("Parent Process ID: %d created Child: %d\n", getpid(), pid);
}
return 0;
}
pthreads)#include <stdio.h>
#include <pthread.h>
void* threadFunction(void* arg) {
printf("Thread executing inside shared process memory!\n");
return NULL;
}
int main() {
pthread_t threadId;
// Creates lightweight execution unit in same address space
pthread_create(&threadId, NULL, threadFunction, NULL);
pthread_join(threadId, NULL);
return 0;
}
Q1: What resource is uniquely private to each individual thread within a process?
Correct Answer: C
Every thread maintains its own independent stack (for tracking local variables and function activation frames) and Program Counter (for tracking current instruction). The heap, code, and files are shared across all threads.
Q2: Why does process context switching take significantly more CPU time than thread context switching?
Correct Answer: B
Switching between isolated processes forces the CPU Memory Management Unit (MMU) to change active page tables and invalidate cached virtual-to-physical address translations in the TLB.
Q3: What critical synchronization issue occurs when multiple threads concurrently modify the same shared variable without locking?
Correct Answer: A
A Race Condition occurs when the final outcome of an operation depends on the unpredictable interleaving of thread execution times. Mutex locks and semaphores are used to prevent this.
A Zombie Process is a child process that has completed execution but still has an entry in the process table because its parent has not yet read its exit status via wait(). An Orphan Process is a child process whose parent process terminated before it; it is immediately adopted by the init or systemd root process (PID 1).
User-Level Threads (ULT) are managed entirely by a user-space runtime library without kernel awareness; context switching is ultra-fast, but a single blocking system call blocks all threads. Kernel-Level Threads (KLT) are scheduled directly by the OS kernel, allowing true parallel execution across multiple CPU cores.
A Deadlock is a state where a set of processes/threads are permanently blocked because each holds a resource and waits for another resource held by another. The 4 Coffman conditions are: 1. Mutual Exclusion, 2. Hold and Wait, 3. No Preemption, and 4. Circular Wait.
No. By definition, a process must contain at least one primary thread of execution (the main thread) to execute code instructions.
Chrome uses a multi-process architecture: each browser tab, extension, and GPU renderer runs as an isolated process. If a JavaScript script in one tab hangs or crashes, only that individual tab process terminates without closing the entire browser window.
Virtual Threads (like Goroutines in Go or Project Loom in Java 21) are lightweight user-mode threads scheduled by the language runtime onto a small pool of carrier OS kernel threads, allowing millions of concurrent tasks with minuscule memory footprints.