Process — Explained with Examples
A process is an independent program in execution with its own memory space, files, and system resources, isolated from other processes.
Processes are the OS-level abstraction for running programs. Each process has its own address space, file descriptors, environment variables, and execution state. Inter-process communication (IPC) includes pipes, sockets, shared memory, and message queues. Context switching between processes is heavier than thread switching because the OS must switch memory mappings and flush caches.
Think of a process like a separate apartment. Each apartment has its own rooms (memory), door (file handles), and utilities (system resources). Neighbors can talk through the hallway (IPC mechanisms) but cannot walk into each other’s apartments. This isolation provides security and stability — one crashing process does not affect others.
Processes are created by the OS when a program starts. The fork() system call creates a child process as a copy of the parent, common in Unix systems.
import multiprocessing
import os
def worker(name):
print(f"Process {name}: PID = {os.getpid()}, Parent PID = {os.getppid()}")
if __name__ == "__main__":
print(f"Main process PID: {os.getpid()}")
processes = []
for i in range(3):
p = multiprocessing.Process(target=worker, args=(i,))
processes.append(p)
p.start()
for p in processes:
p.join()
print("All processes completed")Processes provide strong isolation but incur higher overhead than threads. Use processes for CPU-bound work that benefits from parallelism across cores and needs fault isolation.
Thread, Fork, IPC, Concurrency vs Parallelism
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro