Process vs Thread: The Operating Systems Answer That Doesn't Sound Memorized
"Difference between a process and a thread" is probably the most-asked Operating Systems question. Most answers list a table. A strong answer starts from what each one owns.
A process is a program with its own private world
When you launch a program, the OS creates a process. It gives that process:
- Its own address space (code, data, heap and stack, invisible to other processes)
- Its own open files and resources
- A process control block (PCB) the OS uses to track it
- At least one thread of execution
Because address spaces are private, one process crashing normally does not damage another. That isolation is the whole point.
A thread is a path of execution inside a process
A thread is the unit the CPU actually schedules. Every process has at least one. Extra threads inside the same process:
- Share the code, global data, heap and open files of the process
- Each have their own stack, program counter and register set (they need their own so each can be in a different place in the code)
Think of the process as a house and the threads as the people living in it: they share the kitchen and the rooms (memory and files) but each person has their own thoughts (stack and registers).
An example: a web browser
A browser downloads images, runs scripts, renders the page and responds to your clicks all at once. If it were single-threaded, the whole window would freeze while one image downloads. With threads, one thread downloads while another renders and another handles input, and all of them see the same page data without copying it.
Modern browsers actually use separate processes per tab too, so a crash in one tab does not take the others down. That is a deliberate use of process isolation on top of threads.
Why threads are cheaper
| Operation | Process | Thread |
|---|---|---|
| Creation | Heavy: new address space and resources | Light: reuse the process's resources |
| Context switch | Expensive (memory mapping must change) | Cheaper (same address space) |
| Communication | Needs IPC: pipes, sockets, shared memory, message queues | Just read and write shared variables |
| Isolation | Strong | None: a bad thread can corrupt the whole process |
The catch: shared memory means shared bugs
Threads communicate for free by sharing variables, and that is exactly where trouble starts. Consider two threads incrementing the same counter:
counter = counter + 1
This looks like one step but is really read, add, write. If two threads interleave their steps:
- Thread A reads counter = 5
- Thread B reads counter = 5
- Thread A writes 6
- Thread B writes 6
Two increments happened, but the counter went from 5 to 6, not 7. This is a race condition: the result depends on timing. The fix is synchronization: a mutex, semaphore or atomic operation, so that only one thread executes the critical section at a time. The risk of getting synchronization wrong (including deadlock, where threads wait on each other forever) is the price of the thread model's speed.
User-level vs kernel-level threads
- User-level threads are managed by a library; the kernel sees only the process. Switching is fast, but if one thread blocks on I/O the whole process can block.
- Kernel-level threads are managed by the OS. Switching costs more, but the kernel can run several threads of one process on different CPU cores and block them independently.
Most modern systems use kernel threads (or a mapping between the two).
The two-line viva answer
A process is a program in execution with its own private address space and resources. A thread is a lightweight unit of execution inside a process that shares the process's memory and resources but has its own stack and registers, which makes threads cheaper to create and switch, but riskier because they share data.
Sumantrak™ is an AI mentor built for Indian engineering, diploma, BCA and BSc CS/IT students — Operating Systems, Networks, and the rest of your syllabus, explained like this. Free to start →