🧠 What is a Process?

A process is a program in execution.
It’s the running instance of your code β€” complete with its own memory, state, and system resources.

Think of a process as a living, breathing version of your static code.


🧩 Key Characteristics of a Process

FeatureExplanation
🧠 Code (Text) SegmentThe actual program code (machine instructions)
πŸ“¦ Data SegmentGlobal and static variables
πŸ“š HeapDynamically allocated memory (via malloc, new)
πŸ“„ StackFunction calls, local variables, return addresses
πŸͺͺ PID (Process ID)Unique identifier assigned by OS
⏳ StateRunning, Ready, Blocked, Terminated
⏱️ Program Counter (PC)Address of next instruction
πŸ“Š CPU RegistersStore temporary data
πŸ” IsolationProcesses don’t share memory by default

🧱 Process vs Program

ProgramProcess
Passive entity (just code)Active entity (in execution)
Stored on disk (.exe, .class)Loaded in RAM
Doesn’t do anythingConsumes CPU, memory, I/O
Can have multiple instancesEach instance is a separate process

πŸ” Process Lifecycle States

          β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”
          β”‚ New    β”‚ ← Created by OS
          β””β”€β”€β”¬β”€β”€β”€β”€β”€β”˜
             ↓
         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”
         β”‚ Ready  β”‚ ← Waiting to be scheduled
         β””β”€β”€β”¬β”€β”€β”€β”€β”€β”˜
             ↓
         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”
         β”‚Running β”‚ ← On the CPU now
         β””β”€β”€β”¬β”€β”€β”€β”€β”€β”˜
      β”Œβ”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”
      ↓           ↓
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Blocked  β”‚  β”‚ Terminatedβ”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
  • New: Process is created (e.g., fork() in Linux)

  • Ready: Waiting in the queue for CPU

  • Running: Actively executing instructions

  • Blocked: Waiting for I/O (e.g., file read)

  • Terminated: Finished or killed


πŸ› οΈ Process Control Block (PCB)

The OS uses a PCB to keep track of each process.

Contains
PID
CPU registers
Program counter
Scheduling info
Memory limits
I/O info
Process state

πŸ§ͺ Real-World Example

$ firefox
  • The OS:

    • Loads the Firefox binary

    • Allocates memory for code, heap, stack

    • Assigns PID (e.g., 10234)

    • Tracks it in the scheduler

Now Firefox is a process.


🧠 Interview-Ready Definition:

A process is a program in execution. It includes the program code, current activity (registers, program counter), memory segments (heap, stack, data), and resources assigned by the OS. Processes are isolated from each other and managed via Process Control Blocks (PCBs).