OS Dose | Processes and Threads | Beginner Guide
Your comprehensive guide to processes and threads is a good refresher for those who already know these concepts and even more beneficial for those reading about them for the first time.
Motivation
You open your laptop and start your usual routine—browser, code editor, tons of tabs, each doing its thing: UI rendering, posts loading as you scroll LinkedIn or Facebook. Meanwhile, you're cloning a GitHub repo to tackle a project task. All of this is happening at once, smoothly handled by your OS. Isn’t it worth digging into how all that works behind the scenes?
Concurrency
That expression “happening at the same time/ in parallel“ is what we call concurrency, or in more professional terms: “the simultaneous or overlapping execution of multiple tasks or processes“, or in simpler terms: “multiple computations are happening at the same time“.
Why Concurrency?
Because we don’t want our computers to do only one thing at a time, we need to save time. It’s as simple as that.
Why do you have to know these concepts deeply?
Because if you’re a developer, you’ll probably work with apps/websites that handle hundreds or maybe thousands of users at the same time (depends on your company’s product), and you don’t want your apps to be slow, too :) You’ll need to know how to make your apps as performant as possible, fast, and be able to do many tasks concurrently (at the same time).
Processes
Imagine opening a game on your computer, a web browser, or your favourite code editor; these activities mentioned earlier are about creating processes that will run in the system.
Take a look at this:
This is what appeared when I opened the task manager in my OS (Windows 11). It displays the processes currently running in the system, and how much CPU, RAM (memory), disk, and network they consume.
So, we’re now aware of the definition that processes are instances of programs running on our computers, but we want to go a little bit deeper.
Python Example using multiprocessing.Process:
Let’s say you have 3 big images and you want to resize them in parallel (faster) using the multiprocessing module.
from multiprocessing import Process
from PIL import Image
import os
def resize_image(image_path, output_path, size=(300, 300)):
img = Image.open(image_path)
img = img.resize(size)
img.save(output_path)
print(f"Processed: {image_path}")
if __name__ == '__main__':
images = [
("img1.jpg", "resized_img1.jpg"),
("img2.jpg", "resized_img2.jpg"),
("img3.jpg", "resized_img3.jpg"),
]
processes = []
for input_img, output_img in images:
p = Process(target=resize_image, args=(input_img, output_img))
processes.append(p)
p.start()
for p in processes:
p.join()
print("All images resized.")
We are also able to create processes, not just have them running on our computers because of normal use. And here comes what we’ve been talking about earlier, making your programs able to do many things at once.
Microscopic view of a process🔬
All of this data is stored in a process that is essential for the OS to be able to run it.
The Process control block (PCB): contains the process’s metadata.
Virtual address memory ( stack, heap, data, and text sections: contains function calls, local variables, dynamically allocated memory, static variables, and compiled code (Actual functions/instructions).
Execution context: The live environment of the process:
What system calls it's using
What signals it's handling (
SIGINT,SIGKILL, etc.)Scheduling and time slice management
Whether it’s in user mode or kernel mode
Security Context:
UID/GID: The user/group the process belongs to
Capabilities: What resources the process is allowed to use
Sandboxing (in modern OSes): What it’s restricted from accessing
Open File Descriptors:
Every process keeps a table of open files, sockets, pipes, etc.
All of these parts cooperate to make this process ready and able to be run on your computer.
—> But what are threads? 🤔
Threads
If you Google it, you’ll find something like that:
Microscopic view of a thread🔬
Which makes sense, right? But let’s take this Python example of the image resizer program like the previous one:
from threading import Thread
from PIL import Image
import os
def resize_image(image_path, output_path, size=(300, 300)):
img = Image.open(image_path)
img = img.resize(size)
img.save(output_path)
print(f"Processed: {image_path}")
if __name__ == '__main__':
images = [
("img1.jpg", "resized_img1.jpg"),
("img2.jpg", "resized_img2.jpg"),
("img3.jpg", "resized_img3.jpg"),
]
threads = []
for input_img, output_img in images:
t = Thread(target=resize_image, args=(input_img, output_img))
threads.append(t)
t.start()
for t in threads:
t.join()
print("All images resized.")
You might be saying: “Wait a minute, it’s the same thing with processes, what is the difference then?!“.
If things become confusing now, don’t worry, it’s absolutely normal. And we’ll clarify everything in the next section.
Processes Vs Threads
Common Misconceptions/Myths
There are common misconceptions about the difference between processes and threads. Here are some of these myths and their opposing realities:
Myth 1: Threads are always faster than processes.
→ Reality: Threads can be faster due to shared memory and lower overhead, but this isn't always true. Poor thread management, contention, or synchronization issues can make threaded applications perform worse than multi-process ones.
Myth 2: Threads are isolated like processes.
→ Reality: Threads are not isolated. They share code, data, and file descriptors. An error in one thread (e.g., modifying shared data incorrectly) can easily affect others.
Myth 5: Creating threads is always cheap.
→ Reality: Threads have less overhead than processes, but creating and managing a large number of threads is not free. There's still cost in stack allocation, context switching, and synchronization.
Myth 8: Threads are safer than processes.
→ Reality: Processes are more isolated, which generally makes them safer in terms of fault tolerance and security. Threads are more efficient but riskier when it comes to bugs and vulnerabilities spreading.
Analogy
Imagine you run a photo editing service —Like the above code. You have to resize 3 images: img1.jpg, img2.jpg, and img3.jpg.
Using Threads: Workers in the Same Room
→ You hire 3 assistants (threads), and they all work in the same office (same process).
Characteristics:
They share the same desk, tools, and files.
If one person finds a faster way to do things (e.g., caches a tool), others benefit.
But they can get in each other’s way (e.g., fighting for CPU or memory).
If someone knocks over the power strip (crash), everyone stops.
This is like using threads — faster to set up, shared workspace, but prone to interference.
Using Processes: Freelancers in Separate Studios
→ You hire 3 independent freelancers (processes). Each works from their own studio (separate memory and environment).
Characteristics:
Each has its own copy of the image and software.
They don’t interfere with one another.
One can crash or power down, and the others keep working.
But it’s slower to start up, and they can't easily share results or tools.
This is like using processes — safer and more scalable, but slower to set up and less connected.
Recap
Concurrency means doing many tasks at the same time to make programs faster and more efficient.
Processes are independent programs running separately, with their own memory and resources. They are safer but slower to start.
Threads are smaller units inside processes that share memory. They are faster but riskier because one thread’s error can affect others.
Key difference: Processes are isolated; threads share the same space.
Think of threads as assistants working in the same room, and processes as freelancers working in separate studios.






