OS Notes
Understanding the five process states — new, ready, running, waiting, and terminated — with state transition diagrams, real-world examples, and how the OS manages state changes.
Introduction
A process is not always running on the CPU. In fact, on a system with hundreds of processes and only a few CPU cores, most processes spend most of their time waiting. Understanding process states — where a process is in its lifecycle — is essential for understanding how the operating system schedules and manages work.
Think of it like a patient in a hospital. A patient is not always being treated by a doctor. They might be in the waiting room (ready state), being examined (running state), waiting for lab results (waiting/blocked state), just admitted (new state), or discharged (terminated state). The hospital manages all these patients simultaneously, just as the OS manages processes in various states.
The Five Process States
State 1: New
The process is being created. The OS is allocating resources, setting up the Process Control Block (PCB), and loading the program into memory. The process exists but has not yet been admitted to the ready queue.
State 2: Ready
The process is loaded in memory and ready to execute, but is waiting for CPU allocation. It has everything it needs except the CPU itself. Multiple processes can be in the ready state simultaneously, organized in the ready queue.
State 3: Running
The process is currently executing instructions on the CPU. On a single-core system, only ONE process can be in the running state at any given time. On a multi-core system, one process per core can be running.
State 4: Waiting (Blocked)
The process is waiting for some event to occur — typically I/O completion (disk read, network response), a signal from another process, or a resource to become available. Even if the CPU were free, this process cannot use it because it is waiting for something else.
State 5: Terminated (Exit)
The process has finished execution. The OS is cleaning up — deallocating memory, closing files, releasing resources. The process entry may remain briefly in the process table for the parent to collect the exit status (zombie state in Unix).
State Transitions in Detail
New → Ready (Admitted)
When: Process creation is complete, resources are allocated, and the OS admits it to the ready queue. Example: You type ./myprogram and the shell creates the process — once it is fully loaded in memory, it enters the ready state.
Ready → Running (Dispatched)
When: The CPU scheduler selects this process from the ready queue and the dispatcher gives it the CPU. Example: It is this process's turn in the Round Robin rotation.
Running → Ready (Preempted/Interrupted)
When: The process's time quantum expires, or a higher-priority process becomes ready, or a hardware interrupt occurs. Example: After running for 10ms (the time quantum), the timer interrupt fires, and the scheduler picks another process.
Running → Waiting (I/O or Event Wait)
When: The process requests I/O, waits for a signal, or waits for a resource. Example: The process calls read() to read from disk. Since the disk is much slower than the CPU, the process blocks.
Waiting → Ready (I/O or Event Completion)
When: The event the process was waiting for has occurred. Example: The disk controller signals that the requested data is now in memory. The process moves to ready (not directly to running — it must wait its turn for the CPU).
Running → Terminated (Exit)
When: The process completes execution or is killed. Example: The process executes return 0 from main(), or the OS kills it due to a segfault.
Ready Queue and Wait Queues
The OS maintains queues for processes in different states:
| Ready Queue: [P3] | [P7] → [P1] → [P12] → NULL |
| Disk Wait Queue: [P4] | [P8] → NULL |
| Network Wait Queue: [P2] | [P5] → NULL |
| Keyboard Wait Queue: [P6] | NULL |
When a process completes its I/O, it moves from the specific wait queue to the ready queue.
Context of State in the PCB
The process state is stored in the Process Control Block. When the OS needs to check what a process is doing, it reads the state field from the PCB:
// Process states as defined in Linux kernel (simplified)
#define TASK_RUNNING 0 // Ready or Running
#define TASK_INTERRUPTIBLE 1 // Waiting (can be woken by signal)
#define TASK_UNINTERRUPTIBLE 2 // Waiting (cannot be interrupted)
#define TASK_STOPPED 4 // Stopped (by debugger or signal)
#define TASK_ZOMBIE 32 // Terminated, waiting for parent
struct task_struct {
volatile long state; // Current process state
int pid;
// ... other PCB fields
};Note that Linux combines "ready" and "running" into a single TASK_RUNNING state — the distinction is just whether the process is currently on a CPU core.
Practical Example: Web Browser Loading a Page
Let us trace a browser process through state transitions:
- New: User clicks browser icon. OS creates process, loads code.
- Ready: Process loaded in memory, waiting for CPU.
- Running: CPU executes browser initialization code.
- Waiting: Browser calls connect() to web server — waits for network.
- Ready: Network connection established — process moves to ready queue.
- Running: CPU executes code to send HTTP request.
- Waiting: Waiting for server response (network I/O).
- Ready: Response received — ready to process it.
- Running: CPU parses HTML, builds DOM tree.
- Waiting: Requests images/CSS from server.
- (Cycle continues...)
The process constantly transitions between Running, Ready, and Waiting. This is the CPU-I/O burst cycle in action.
Real-World Analogy
Process states are like the states of a restaurant order:
- New: Order placed but kitchen has not started preparing
- Ready: Ingredients gathered, recipe prepared, waiting for a free chef (CPU)
- Running: Chef is actively cooking the dish
- Waiting: Dish is in the oven (I/O) — chef works on other orders
- Terminated: Dish served to customer, order closed
Key Takeaways
- Every process exists in one of five states: New, Ready, Running, Waiting, or Terminated
- Only ONE process per CPU core can be in the Running state
- The transition from Ready → Running is controlled by the CPU scheduler
- The transition from Running → Waiting is initiated by the process itself (I/O request)
- Waiting → Ready happens when the awaited event completes (NOT directly to Running)
- Preemption moves a process from Running back to Ready (timer interrupt)
- The OS maintains separate queues for ready processes and for each type of wait condition
Exam Focus
Revise definitions, diagrams, examples, and short-answer points for Process States.
Interview Use
Prepare one clear explanation, one practical example, and one common mistake for this Operating Systems topic.
Search Terms
operating-systems, operating systems, operating, systems, process, management, states, process states
Related Operating Systems Topics