Siksha Sarovar

Siksha Sarovar (sikshasarovar.com) is a free educational web application that helps students in India learn programming and prepare for academic and competitive exams. The platform offers structured coding courses (C, C++, Python, Java, HTML, CSS, PHP, Power BI, AI, Machine Learning, Data Science), complete university curriculum notes for BCA/MCA students with previous year question papers, Class 10 and Class 12 CBSE/HBSE school notes, and dedicated preparation material for SSC, UPSC, Banking, Railway and other government exams. Browsing the site is completely free and requires no account. Users may optionally sign in with Google solely to save their learning progress, quiz scores and personal preferences across devices.

Privacy Policy | Terms of Service | Contact Siksha Sarovar | About Siksha Sarovar

v4.0.9 · PWA
Siksha Sarovar logo
Siksha Sarovar
Your Learning Universe

Siksha Sarovar is a free e-learning platform for coding courses, BCA university notes and competitive exam preparation. Optional Google sign-in saves your learning progress across devices.

Initializing knowledge base…
Compiling modules 0%

Process State Transitions

Lesson 20 of 32 in the free Design of Unix Operating System notes on Siksha Sarovar, written by Rohit Jangra.

Introduction

A UNIX process does not run continuously. It goes through several states during its lifetime. The kernel manages these transitions based on events like I/O completion, scheduling decisions, and signals.

Process States in UNIX

1. User Running:

  • The process is executing in user mode (running user code).

2. Kernel Running:

  • The process is executing in kernel mode (executing a system call or handling an interrupt).

3. Ready to Run (In Memory):

  • The process is ready to execute and is waiting in memory for the scheduler to assign the CPU.

4. Asleep in Memory (Sleeping):

  • The process is waiting for an event (e.g., I/O completion, resource availability).
  • It is in memory but not eligible for CPU time.

5. Ready to Run (Swapped):

  • The process is ready to run but has been swapped out to disk due to insufficient memory.

6. Sleeping (Swapped):

  • The process is sleeping AND has been swapped to disk.

7. Preempted:

  • The kernel has decided to run a higher-priority process, so this process is temporarily set aside.
  • It is ready to run and will resume when scheduled.

8. Created:

  • The process has been created (fork() has been called) but is not yet ready to run.
  • The kernel is setting up data structures.

9. Zombie:

  • The process has terminated (exit() called) but its parent has not yet called wait().
  • The process table entry still exists to provide the exit status to the parent.
  • No resources are held except the process table entry.

State Transition Diagram

                    fork()
                      │
                      ▼
                 ┌─────────┐
                 │ Created  │
                 └────┬────┘
      enough memory   │   not enough memory
         ┌────────────┴──────────────┐
         ▼                           ▼
  ┌──────────────┐          ┌────────────────┐
  │ Ready to Run │          │ Ready to Run   │
  │ (In Memory)  │◄────────►│ (Swapped Out)  │
  └──────┬───────┘  swap    └────────────────┘
         │ scheduled                ▲
         ▼                         │ swap out
  ┌──────────────┐                 │
  │Kernel Running│─────────────────┤
  └──┬───────┬───┘                 │
     │       │ sleep               │
     │       ▼                     │
     │  ┌──────────────┐    ┌────────────────┐
     │  │  Asleep in   │───►│  Sleeping      │
     │  │   Memory     │    │  (Swapped)     │
     │  └──────┬───────┘    └────────┬───────┘
     │         │ wakeup              │ wakeup
     │         ▼                     │
     │  ┌──────────────┐             │
     │  │ Ready to Run │◄────────────┘
     │  │ (In Memory)  │
     │  └──────────────┘
     │
     │ return to user
     ▼
  ┌──────────────┐
  │ User Running │
  └──────┬───────┘
         │ exit()
         ▼
  ┌──────────────┐
  │   Zombie     │
  └──────────────┘

Key Transitions

FromToTrigger
CreatedReady (Memory)Process setup complete, memory available
CreatedReady (Swapped)Not enough memory
Ready (Memory)Kernel RunningScheduler selects this process
Kernel RunningUser RunningReturn from system call / interrupt
User RunningKernel RunningSystem call or interrupt occurs
Kernel RunningAsleep (Memory)Waiting for I/O or resource
Asleep (Memory)Ready (Memory)Event/resource becomes available (wakeup)
Kernel RunningReady (Memory)Preempted by higher-priority process
Kernel RunningZombieProcess calls exit()
Ready/Asleep (Memory)(Swapped)Swapper swaps process to disk
(Swapped)(In Memory)Swapper swaps process back in

Summary

  • UNIX processes go through 9 states during their lifetime.
  • Transitions are triggered by system calls, scheduling, I/O events, and memory management.
  • A zombie process has exited but hasn't been collected by its parent.
  • Swapping moves processes between memory and disk to manage limited RAM.