Skip to main content

States of a Process

State of Process

State and Lifecycle of Process

Understanding the different states a process can be in is crucial for grasping how operating systems manage tasks. Each state represents a specific condition or stage in the lifecycle of a process, from creation to completion.

New​

The New state is when a program is loaded into memory by the operating system, and a process is being created.

At this stage, the process is not yet ready to execute. It is undergoing initialization, and the Long Term Scheduler decides whether this process should be admitted into memory based on system workload.

Ready​

In the Ready state, the process is loaded into memory and is ready to run. It is waiting for the CPU scheduler to assign it CPU time.

Processes in the ready state are waiting in the ready queue. The CPU Scheduler decides which of these processes will execute next.

Running​

The Running state is when the process is actively executing on the CPU.

In this state, the process has all the necessary resources and is being processed by the CPU. Only one process can be in the running state on a single-core CPU at a given time.

Waiting​

The Waiting state occurs when a process cannot continue until a specific event happens.

Common reasons for a process to be in the waiting state include waiting for I/O operations to complete, waiting for a signal, or waiting for a resource to become available. In this state, the process does not use the CPU.

Terminated​

The Terminated state signifies that the process has finished execution or has been stopped by the operating system.

Once a process reaches the terminated state, its resources are released, and it is removed from the process table. The process can reach this state either by completing its execution successfully or being terminated due to an error or external intervention.

Example Scenario​

Consider a scenario where a program reads data from a file, processes it, and then writes the results to another file:

  1. New: The OS loads the program into memory and sets up the necessary data structures.

  2. Ready: The process is initialized and waiting in the ready queue for CPU time.

  3. Running: The process starts executing and tries to read from the input file.

    Note

    The scheduler determines which process moves to the running state, while the dispatcher handles the actual context switching.

  4. Waiting: The process issues an I/O request to read the file and moves to the waiting state until the I/O operation completes.

  5. Ready: The I/O operation completes, and the process moves back to the ready state, awaiting CPU time.

  6. Running: The process resumes execution, processes the data, and prepares to write the results to another file.

  7. Waiting: The process issues an I/O request to write to the output file and waits for this operation to complete.

  8. Ready: The I/O operation completes, and the process is moved back to the ready state.

  9. Running: The process resumes execution, finishes processing, and then prepares to exit.

  10. Terminated: The process has finished execution, and the OS cleans up the resources allocated to it.

Note

A process can also transition from Running to Ready state due to an interrupt, such as when its time quantum expires, prompting a context switch so another process can be scheduled for CPU time.

Understanding these states helps in comprehending how an operating system manages process scheduling, multitasking, and resource allocation efficiently.