Skip to Content
Go Realm v1 is released 🎉
OSProcess & Thread

Process, Thread, and Task

1. Process

A process is an instance of a running program. It has its own memory space, system resources, and execution state.

Key Characteristics:

  • Each process runs independently.
  • Processes do not share memory (unless explicitly using IPC - Inter-Process Communication).
  • Heavyweight (takes more time to create and terminate).
  • Managed by the OS.

Example:

  • When you open Google Chrome and Microsoft Word, they run as separate processes.
  • If one crashes, the other remains unaffected.

2. Thread

A thread is the smallest unit of execution within a process. Multiple threads share the same memory space.

Key Characteristics:

  • Lightweight compared to processes.
  • Threads within the same process share memory and resources.
  • Faster context switching than processes.
  • If one thread crashes, it can affect the entire process.

Example:

  • A web browser uses multiple threads:
    • One thread loads a webpage.
    • Another thread plays a video.
    • A third thread handles user input.

3. Task

A task is a unit of work that needs to be executed. It can be a process, a thread, or an operation scheduled by the OS.

Key Characteristics:

  • A broader term than a process or thread.
  • Can refer to a single operation or a set of instructions.
  • Used in scheduling (e.g., in real-time operating systems).

Example:

  • Printing a document while editing another in Microsoft Word involves multiple tasks (UI handling, background printing).

Threads sit right in between process and task — they’re the actual execution units inside a process.


Process → Thread → Task Relationship

  • Process = the container (memory, resources, files, environment)
  • Thread = the worker inside that container (runs instructions)
  • Task = the actual work the thread executes

Analogy:

  • Process = Kitchen
  • Thread = Chef in the kitchen
  • Task = Cooking a specific dish

  • Process = Office building
  • Thread = Employee in the office
  • Task = Assignment given to the employee

How They Relate

  • A process can have one or many threads.
  • Each thread shares the process’s memory and resources.
  • A task can be run by a single thread or spread across multiple threads.

In Go

  • Go programs usually run as a single process.
  • Inside, goroutines are like tasks, but the Go runtime maps them to OS threads under the hood.
  • Multiple goroutines can share the same OS thread, or be moved to different threads dynamically.

Questions

  • Q: What is the difference between a process and a thread?
    A: Processes are independent with separate memory, while threads share memory and are lightweight.

  • Q: Can threads communicate directly?
    A: Yes, since they share memory. Processes need IPC (pipes, sockets, shared memory).

  • Q: Why use multithreading?
    A: For parallelism, responsiveness (UI thread + worker thread), and efficiency.

Real-world Scenarios

  • Web Server: Uses multiple threads to handle requests.
  • Gaming: One thread for rendering, another for AI.

Avoid Common Mistakes

  • ❌ Don’t say “Process and thread are the same.”
  • ✅ Instead: “Threads are subsets of a process and share resources.”

Key Differences

FeatureProcessThreadTask
DefinitionIndependent program instanceSub-unit of a processUnit of work (can run in a process/thread)
Memory SpaceSeparate per processShared within a processDepends on where it runs
Overhead / Creation CostHigh (OS allocates resources)Medium (shares process resources)Low (could just be a function call)
CommunicationNeeds IPC (pipes, sockets)Can share variables directlyN/A (depends on thread/process)
LifetimeUntil process endsUntil process ends or thread finishesUntil work completes
OS RoleSchedules processesSchedules threadsScheduled via threads/process
Crash ImpactDoes not affect other processesCan crash the entire processDepends on process/thread stability
ExampleRunning Chrome & Word separatelyMultiple tabs in ChromePrinting while editing

Final Thoughts

  • Process = Independent program (Chrome, Word).
  • Thread = Lightweight sub-process (multiple tabs in Chrome).
  • Task = General term for work (can be a process or thread).

Pro Tip: Relate to real-world examples (e.g., “Chrome uses multiple processes for security, and each tab may have threads for faster loading”).