R
Rishtaara
Operating Systems Fundamentals
Lesson 2 of 8Article18 minFREE

Processes and Threads

Processes and Threads

Conceptual differences

  • Process: independent address space and resources.
  • Thread: execution unit within a process, shares memory.
  • Context switching between threads is typically cheaper than between processes.

Threading example

Two Python threads doing work
import threading
import time

def worker(name):
    for i in range(3):
        print(f"{name} -> step {i}")
        time.sleep(0.2)

t1 = threading.Thread(target=worker, args=("A",))
t2 = threading.Thread(target=worker, args=("B",))
t1.start()
t2.start()
t1.join()
t2.join()