Process States

Definition

Process States are the different conditions in which a process can exist during its lifetime. As a process executes, it transitions between different states based on events like CPU allocation, I/O completion, and resource availability. Understanding process states is essential for comprehending how OS schedules and manages processes.

Five Process States

1. New State

Definition: Process has just been created but not yet admitted to the ready queue by OS.

What Happens:

  • Program loaded into memory
  • Process Control Block (PCB) created
  • Memory allocated
  • Process not yet eligible for execution

Transition:

  • To Ready state when OS admits process

Example:

  • Click on program icon
  • OS loads executable file
  • Sets up memory
  • Process in “new” state briefly

2. Ready State

Definition: Process is prepared to execute and waiting for CPU assignment.

What Happens:

  • Process in memory
  • Has all resources except CPU
  • Waiting in ready queue
  • Next in line for CPU

Characteristics:

  • Can start immediately when CPU available
  • Multiple processes in ready state
  • OS scheduler selects which runs

Transition:

  • To Running when CPU scheduler picks it
  • Back to Ready if interrupted (time slice expires)

Example:

  • 5 processes waiting for CPU
  • All in ready state
  • OS scheduler picks one with highest priority

3. Running State

Definition: Process is executing on the CPU right now.

What Happens:

  • Process instructions executing
  • Has access to CPU
  • Using memory and registers
  • Using I/O devices if needed

Characteristics:

  • Only one process per CPU in running state
  • In multi-core: multiple processes can run simultaneously
  • Has allocated time slice (if time-sharing)
  • Can access system resources

Transition Options:

  1. To Waiting: When I/O needed
  2. To Ready: When time slice expires or preempted
  3. To Terminated: When finished

Example:

  • Process executing calculations
  • Making disk read request
  • Printing output

4. Waiting State (Blocked State)

Definition: Process is waiting for some event to occur and cannot proceed until that event happens.

What Happens:

  • Process suspended
  • Waiting for I/O operation to complete
  • Waiting for signal/message
  • Waiting for other resource
  • CPU cannot be used while waiting

Why Waiting:

  • I/O Waiting (most common):
    • Reading from disk
    • Writing to disk
    • Reading from network
    • Waiting for user input from keyboard
    • Waiting for printer
  • Other Events:
    • Waiting for another process to signal
    • Waiting for timer to expire
    • Waiting for resource to become available
    • Waiting for lock to be released

Characteristics:

  • Process cannot progress
  • CPU can be used by other processes
  • Waiting queue maintained by OS
  • Does not take CPU time (good!)

Transition:

  • To Ready: When waiting event occurs
  • Cannot go directly to Running

Example:

Process reads file from disk:
1. Process issues read command
2. Goes to waiting state
3. Disk reads file (takes time)
4. I/O completes, process goes to ready
5. Waits for CPU to be available
6. CPU assigned, goes to running

5. Terminated State

Definition: Process has finished execution or was forcibly terminated.

What Happens:

  • Process stops executing
  • Memory deallocated
  • Resources released
  • PCB may remain temporarily
  • Process no longer active

Reasons for Termination:

  • Normal Completion: Program finished successfully
  • Exception: Division by zero, illegal instruction
  • Explicit Termination: Kill command, process.exit()
  • Timeout: Exceeded maximum runtime
  • Resource Unavailable: Critical resource unavailable

Characteristics:

  • Process will not execute again
  • Memory freed for other processes
  • I/O devices released
  • Exit code/status available to parent

Transition:

  • Terminal state (no further transitions)

Example:

  • Program finishes execution
  • Returns exit code 0 (success) or non-zero (error)
  • Resources cleaned up
  • Process entry removed from process list

Process State Transitions (Diagram)

         Admit
        ─────→  ┌────────┐
New            │ Ready  │
              └────────┘
                ↑    │
   Timeout      │    │ Scheduler
   Preemption   │    │ dispatch
                │    ↓
              ┌──────────┐
              │ Running  │
              └──────────┘
                ↑    │
                │    │ I/O request
                │    │ wait signal
                │    ↓
                │  ┌─────────┐
  I/O complete │  │ Waiting │
  Signal       │  │ (Blocked)│
  Wakeup       └──┤         │
                  └─────────┘

              Exit/Terminate


               ┌──────────┐
               │Terminated│
               └──────────┘

State Transitions Detailed

Ready → Running

When: OS scheduler selects process from ready queue By: Scheduler/dispatcher Reason: CPU is free and process selected

Running → Ready

When: Time slice/quantum expires (in time-sharing) By: Timer interrupt Reason: Other processes need CPU time (fairness)

Running → Waiting

When: Process needs I/O or resource By: Process requests I/O Reason: Waiting for I/O to complete or resource to become available

Example:

read(file);  // Process requests read
→ Transitions to Waiting state
→ Waits for disk I/O

Waiting → Ready

When: I/O operation completes or resource becomes available By: I/O subsystem or other process Reason: Process can now proceed

Example:

Disk read completes
→ Waiting process transitions to Ready
→ Joins ready queue
→ Waits for CPU scheduler to pick it

Running → Terminated

When: Process completes execution By: Process itself or OS (if forced kill) Reason: Successful completion or error condition

Any → Terminated

When: Kill command or termination signal By: User or OS Reason: Force termination (process not responding, user kills it)

Important Notes

Ready vs Waiting

Ready:

  • Has everything needed except CPU
  • Can run immediately
  • Waiting in queue for CPU

Waiting:

  • Missing something (I/O, resource)
  • Cannot proceed even if CPU available
  • Will not be ready until event occurs

Preemption vs Voluntary

Preemption (Ready ← Running):

  • OS forcibly takes CPU
  • Time slice expires
  • Higher priority process arrives
  • Process doesn’t volunteer

Voluntary (Running → Waiting):

  • Process asks for I/O
  • Process asks for resource
  • Process goes to waiting state
  • Process gives up CPU

Number of Processes in Each State

In Real System:

  • New: Usually 0-1 (brief)
  • Ready: Depends on load (can be many)
  • Running: 1 per CPU core
  • Waiting: Many (processes waiting for I/O)
  • Terminated: 0 (cleaned up immediately)

Typical Distribution (4-core CPU):

Ready Queue: 8 processes
Running: 4 processes (one per core)
Waiting: 20 processes (I/O operations)

Process State in PCB

Process Control Block contains current state:

Process Control Block (PCB)
├── PID: 1234
├── State: Waiting
├── Program Counter: 0x401234
├── Registers: {...}
├── Memory: base=0x10000, limit=0x20000
├── I/O: Waiting for disk read
└── Priority: 5

Exam Important Points

  1. Define five process states
  2. Characteristics of each state
  3. When and why transitions occur
  4. Ready vs Waiting differences
  5. Preemption vs voluntary transitions
  6. State transition diagram
  7. Typical distributions in real system
  8. Role of OS scheduler
  9. Role of I/O subsystem
  10. Terminated processes cleanup