Skip to main content

Command Palette

Search for a command to run...

Unit 10: Process States and Process Queues | Operating Systems

Updated
6 min readView as Markdown
Unit 10: Process States and Process Queues | Operating Systems

A process does not remain in the same state throughout its lifetime. As it executes and interacts with the CPU and I/O devices, it moves between different process states. The Operating System manages these processes using different process queues.


1. Process States

As a process executes, its state changes according to the activity it is performing.

A process may be in one of the following states:

                 ┌──────────┐
                 │   New    │
                 └────┬─────┘
                      │
                      ▼
                 ┌──────────┐
          ┌─────►│  Ready   │◄─────┐
          │      └────┬─────┘      │
          │           │             │
          │           ▼             │
          │      ┌──────────┐       │
          │      │ Running  │       │
          │      └────┬─────┘       │
          │           │             │
          │           ▼             │
          │      ┌──────────┐       │
          └──────│ Waiting  │───────┘
                 └──────────┘
                      │
                      ▼
                 ┌───────────┐
                 │Terminated │
                 └───────────┘

a. New

The process is being created.

The Operating System is preparing the program and converting it into a process.

New → Process is being created


b. Running

The instructions of the process are currently being executed.

The CPU is allocated to the process.

Running → Instructions are being executed


c. Waiting

The process is waiting for an event, commonly an I/O operation to complete.

For example:

Running
   │
   ▼
I/O Request
   │
   ▼
Waiting

Waiting → Waiting for I/O or another required event


d. Ready

The process is present in main memory and is ready to execute, but it is waiting to be assigned to a processor.

Ready → Waiting for CPU allocation


e. Terminated

The process has completed its execution.

After termination, the OS performs the required cleanup and the process's PCB entry is removed from the process table.

Terminated → Process has finished execution


2. Process Queues

The Operating System maintains different queues to organize processes according to their current state.

The three important process queues are:

  1. Job Queue

  2. Ready Queue

  3. Waiting Queue


a. Job Queue

The Job Queue contains processes that are in the New state.

Characteristics

  • Processes are in the New state.

  • They are initially present in secondary storage.

  • The Long-Term Scheduler (LTS) selects processes from the job pool.

  • Selected processes are loaded into main memory for execution.

Secondary Memory
      │
      ▼
┌─────────────────┐
│    Job Queue    │
│                 │
│  P1   P2   P3   │
└────────┬────────┘
         │
         │ Long-Term Scheduler
         ▼
   Main Memory

Long-Term Scheduler (LTS)

The Long-Term Scheduler, also called the Job Scheduler, selects processes from the job queue and loads them into memory.


b. Ready Queue

The Ready Queue contains processes that are in the Ready state.

Characteristics

  • Processes are in the Ready state.

  • Processes are present in main memory.

  • They are waiting for CPU allocation.

  • The Short-Term Scheduler selects a process from the ready queue.

  • The selected process is dispatched to the CPU.

              Main Memory
                   │
                   ▼
          ┌─────────────────┐
          │   Ready Queue   │
          │                 │
          │  P1   P2   P3   │
          └────────┬────────┘
                   │
                   │ Short-Term Scheduler
                   ▼
                CPU

Short-Term Scheduler

The Short-Term Scheduler, also called the CPU Scheduler, selects a process from the ready queue and assigns it to the CPU.


c. Waiting Queue

The Waiting Queue contains processes that are in the Waiting state.

These processes are waiting for an I/O operation or another event to complete.

             ┌───────────────┐
             │ Waiting Queue │
             │               │
             │  P2   P4   P5 │
             └───────┬───────┘
                     │
                  I/O/Event
                     │
                     ▼
                Ready Queue

3. Process Queues Overview

The overall movement of processes can be represented as:

                     Secondary Memory
                            │
                            ▼
                     ┌────────────┐
                     │ Job Queue  │
                     └─────┬──────┘
                           │
                    Long-Term Scheduler
                           │
                           ▼
                       Main Memory
                           │
                           ▼
                     ┌────────────┐
                     │Ready Queue │
                     └─────┬──────┘
                           │
                   Short-Term Scheduler
                           │
                           ▼
                          CPU
                           │
              ┌────────────┴────────────┐
              │                         │
              ▼                         ▼
          Execution                I/O Request
              │                         │
              │                         ▼
              │                  ┌──────────────┐
              │                  │Waiting Queue │
              │                  └──────┬───────┘
              │                         │
              │                      I/O Done
              │                         │
              └─────────────────────────┘
                           │
                           ▼
                      Ready Queue

4. Degree of Multiprogramming

The Degree of Multiprogramming is the number of processes present in main memory at a given time.

Degree of Multiprogramming = Number of processes in memory

For example:

Main Memory

┌──────────────────────┐
│ Process P1           │
│ Process P2           │
│ Process P3           │
│ Process P4           │
└──────────────────────┘

Degree of Multiprogramming = 4

Role of Long-Term Scheduler

The Long-Term Scheduler (LTS) controls the degree of multiprogramming by deciding which processes should be admitted into main memory.

More processes admitted
          ↓
Higher degree of
multiprogramming

5. Dispatcher

The Dispatcher is an OS component that gives control of the CPU to the process selected by the short-term scheduler.

The basic flow is:

Ready Queue
     │
     ▼
Short-Term Scheduler
     │
     │ Selects process
     ▼
Dispatcher
     │
     │ Gives CPU control
     ▼
Running Process

Main Functions of Dispatcher

The dispatcher:

  • Switches the CPU to the selected process.

  • Performs the necessary context switch.

  • Transfers control to the appropriate execution location of the selected process.

Scheduler selects the process; Dispatcher gives the CPU to that process.


Quick Revision

Concept Meaning
New Process is being created
Ready Waiting for CPU allocation
Running Instructions are being executed
Waiting Waiting for I/O or an event
Terminated Execution has finished
Job Queue Contains new processes
Ready Queue Contains ready processes
Waiting Queue Contains waiting processes
LTS Selects processes from Job Queue
Short-Term Scheduler Selects process from Ready Queue
Dispatcher Gives CPU control to selected process
Degree of Multiprogramming Number of processes in main memory

Key Takeaway

Job Queue
   ↓
Long-Term Scheduler
   ↓
Ready Queue
   ↓
Short-Term Scheduler
   ↓
Dispatcher
   ↓
CPU
   ↓
Running
   ↓
Waiting ──────► Ready
   │
   ▼
Terminated

The OS uses process states and queues to efficiently manage processes and CPU utilization.

More from this blog

S

Shivaraj Taware

10 posts

Learning OS from the ground up sharing notes, insights, and code as I explore processes, memory, file systems, scheduling, and more. 𝐀 𝐣𝐨𝐮𝐫𝐧𝐚𝐥 𝐟𝐨𝐫 𝐥𝐞𝐚𝐫𝐧𝐞𝐫𝐬, 𝐛𝐲 𝐚 𝐥𝐞𝐚𝐫𝐧𝐞𝐫