Processes, Threads, Concurrency, Multithreading, and Multiprocessing - Full Notes with Python Examples
Table of Contents
Processes
A process is a running instance of a program, containing its own memory space, program counter, registers, and stack (TutorialsPoint, n.d.). Each process is isolated, and processes communicate via inter-process communication (IPC) mechanisms like pipes, sockets, or shared memory (GeeksforGeeks, 2024).
Example in Python:
1
2
3
4
5
6
7
8
9
10
11
12
import os
def child_process():
print(f"Child process ID: {os.getpid()}")
if __name__ == "__main__":
# method to create a child process only available in Unix/Linux
pid = os.fork()
if pid == 0:
child_process()
else:
print(f"Parent process ID: {os.getpid()}")
Here, fork()
creates a new process (child).
Processes have a lifecycle: New, Ready, Running, Waiting, and Terminated (TutorialsPoint, n.d.).
Threads
A thread is the smallest unit of CPU execution inside a process. Multiple threads can exist within the same process, sharing memory and resources but having independent execution flows (GeeksforGeeks, 2025).
Example in Python:
1
2
3
4
5
6
7
8
9
import threading
def thread_function():
print(f"Thread running: {threading.current_thread().name}")
if __name__ == "__main__":
t = threading.Thread(target=thread_function)
t.start()
t.join()
Threads are lightweight compared to processes since they share address space (GeeksforGeeks, 2025).
Processes vs Threads
Feature | Process | Thread |
---|---|---|
Memory | Separate memory space | Shared memory within process |
Communication | IPC mechanisms (slow) | Direct memory access (fast) |
Overhead | High (context switch is heavy) | Low (lightweight switching) |
Fault Tolerance | Crash isolated | Crash may affect all threads |
Creation | Heavyweight (more resources) | Lightweight (less resources) |
Scheduling | OS-level scheduling | User-level scheduling |
Concurrency vs Parallelism
Concurrency is the ability to manage multiple tasks at the same time, but not necessarily simultaneously. Tasks start, run, and complete in overlapping time periods (GeeksforGeeks, 2024).
Parallelism is when tasks literally run at the same time, typically on multiple cores (Splunk, 2025).
Aspect | Concurrency | Parallelism |
---|---|---|
Definition | Multiple tasks in progress (may not run together) | Multiple tasks running at the same instant |
Hardware | Can work on single or multiple cores | Requires multiple cores/processors |
Example | Multitasking on a single CPU | Tasks split across multiple CPUs/cores |
Focus | Structure and coordination | Speed and simultaneous execution |
Python Usage | threading, asyncio | multiprocessing, joblib |
Illustration:
- Concurrency: A single cashier multitasking between customers.
- Parallelism: Multiple cashiers serving different customers simultaneously.
Python Example for Concurrency (threads):
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
import threading
import time
def task(name):
print(f"Starting {name}")
time.sleep(2)
print(f"Ending {name}")
if __name__ == "__main__":
t1 = threading.Thread(target=task, args=("Thread-1",))
t2 = threading.Thread(target=task, args=("Thread-2",))
t1.start()
t2.start()
t1.join()
t2.join()
Python Example for Parallelism (multiprocessing):
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
import multiprocessing
import time
def task(name):
print(f"Starting {name}")
time.sleep(2)
print(f"Ending {name}")
if __name__ == "__main__":
p1 = multiprocessing.Process(target=task, args=("Process-1",))
p2 = multiprocessing.Process(target=task, args=("Process-2",))
p1.start()
p2.start()
p1.join()
p2.join()
Conclusion
Concurrency and parallelism are core concepts for modern operating systems and programming.
- Concurrency is about dealing with lots of things at once.
- Parallelism is about doing lots of things at the same time.
Threads offer lightweight concurrency, while processes offer heavyweight isolation and true parallelism (GeeksforGeeks, 2024).
References
GeeksforGeeks. (2024, September 15). Difference between Multiprocessing and Multithreading. GeeksforGeeks. https://www.geeksforgeeks.org/difference-between-multiprocessing-and-multithreading/
GeeksforGeeks. (2024, December 28). Concurrency in Operating System. GeeksforGeeks. https://www.geeksforgeeks.org/concurrency-in-operating-system/
GeeksforGeeks. (2025, February 21). Thread in Operating System. GeeksforGeeks. https://www.geeksforgeeks.org/thread-in-operating-system/
Panigrahi, K. K. (2022, December 16). Difference Between Process and Thread. TutorialsPoint. https://www.tutorialspoint.com/difference-between-process-and-thread
Splunk. (2025, April 23). Concurrency in Programming and Computer Science: The Complete Guide. Splunk. https://www.splunk.com/en_us/blog/learn/concurrency.html
TutorialsPoint. (n.d.). Operating System - Operations on Processes. TutorialsPoint. https://www.tutorialspoint.com/operating_system/os_operations_on_processes.htm