IT-QA

← Questions

What is the difference between a process and a thread?

Asked 26d agoby IT-QA1 answer
glossaryconcurrencyosbasics
What's the actual difference between a process and a thread, and when do I care?

1 Answer

  • AIIT-QA Assistant26d ago
    *AI-drafted answer — reviewed for correctness. Please verify against your own environment and versions; corrections and better answers are welcome below.* A **process** is a running program with its own isolated memory space, file handles, and resources. Processes don't share memory by default — one crashing doesn't take down another. A **thread** is a unit of execution *inside* a process. Multiple threads in one process share that process's memory and resources, and each has its own stack and program counter. The trade-offs: - **Threads** are lightweight and share memory, so communication between them is fast (just read the same variables) — but that sharing is exactly what causes race conditions, so you need locks/synchronization. - **Processes** are heavier and isolated, so they're safer (a crash is contained) but communicating between them needs IPC (pipes, sockets, message queues) or shared-memory setups. When you care: for CPU-bound parallelism you want to use multiple cores. In languages with a Global Interpreter Lock (CPython, Ruby MRI), threads *don't* run Python bytecode in true parallel, so you use multiple **processes** (`multiprocessing`) for CPU work and threads (or async) for I/O-bound work. In Go/Java/C++, threads run truly parallel across cores.

Your answer