Processes and Threads in Operating System

Processes and Threads in Operating Systems

Welcome back to our Operating System series! In our last post, we explored different types of operating systems. Now, let’s dive into the core units of execution that an OS manages: Processes and Threads.


What Is a Process?

Process Management

A process is simply a program in execution. Whenever you open a browser, play a game, or run a code editor — each action creates a process.

🧾 Key Difference: A program is a passive file (code), but a process is an active entity (running code in memory).

Key Characteristics of a Process:

  • Has its own memory space
  • Contains code, data, stack, and heap
  • Managed independently by the OS
  • Assigned a unique process ID (PID)

Example:

When you open Chrome and VS Code at the same time:

  • Chrome = Process 1
  • VS Code = Process 2

Both run independently, with separate memory and states.


What Is a Thread?

Threads in OS

A thread is the smallest unit of execution within a process.

You can think of a thread as a lightweight process that shares the same memory of its parent process but executes independently.

Key Characteristics of a Thread:

  • Shares memory and resources with its parent process
  • Has its own registers, stack, and program counter
  • Faster to create and manage than processes

Process vs Thread Comparison

Feature Process Thread
Memory Has its own memory Shares memory with parent process
Overhead More (heavyweight) Less (lightweight)
Communication Slower (needs IPC) Faster (shared memory)
Dependency Independent Dependent on parent process

Real-Life Analogy

Process = A company
Thread = Employees inside the company

  • Each company works separately (process)
  • Inside each company, multiple employees (threads) work on different tasks simultaneously

Life Cycle of a Process

A process goes through the following states:

  1. New → Created but not yet running
  2. Ready → Waiting to be assigned to CPU
  3. Running → Currently being executed
  4. Waiting → Waiting for I/O (like file or input)
  5. Terminated → Finished execution

Multithreading in OS

Modern OS allows multithreading, where a single process can have multiple threads running in parallel.

💡 Examples:

  • A browser:
    • One thread loads images
    • Another handles user input
    • Another loads the webpage script

Summary

Term Description
Process Program in execution with its own memory
Thread Smallest unit of execution inside a process
OS Role Manages, schedules, and terminates processes/threads

Final Thoughts

Processes and threads form the core of multitasking in operating systems.
Understanding how they work helps you debug faster, write better code, and build scalable systems.

Leave a Reply

Your email address will not be published. Required fields are marked *