WikiGalaxy

Personalize

Process States and Life Cycle in Operating Systems

Introduction to Process States

  • New: The process is being created.
  • Ready: The process is waiting to be assigned to a processor.
  • Running: Instructions are being executed.
  • Waiting: The process is waiting for some event to occur.
  • Terminated: The process has finished execution.

Process Life Cycle

The process life cycle in an operating system describes the journey of a process from creation to termination. It involves various states that a process transitions through during its lifetime.

State Transitions

  • New to Ready: When a process is admitted to the system.
  • Ready to Running: When the scheduler assigns CPU to the process.
  • Running to Waiting: When a process needs to wait for an event.
  • Running to Ready: When a process is preempted by the scheduler.
  • Waiting to Ready: When the event for which the process was waiting occurs.
  • Running to Terminated: When a process finishes its execution.

Example: Process Creation

In this example, we illustrate the transition from the New state to the Ready state when a process is created.


    class ProcessCreation {
      public static void main(String[] args) {
          System.out.println("Process is created and ready to be scheduled.");
      }
    }
    

This simple example demonstrates how a process is initialized and enters the Ready state, waiting for CPU time allocation.

Example: Process Scheduling

This example shows the transition from the Ready state to the Running state when the process is scheduled by the CPU.


    class ProcessScheduling {
      public static void main(String[] args) {
          System.out.println("Process is now running.");
      }
    }
    

Once the CPU scheduler selects a process, it transitions from Ready to Running, allowing it to execute its instructions.

Example: Waiting for I/O

This example illustrates the transition from Running to Waiting when a process requires I/O operations.


    class ProcessIO {
      public static void main(String[] args) {
          System.out.println("Process is waiting for I/O operation.");
      }
    }
    

When a process requests I/O operations, it moves to the Waiting state until the required resources are available.

Example: Process Termination

This example highlights the transition from Running to Terminated when a process completes its execution.


    class ProcessTermination {
      public static void main(String[] args) {
          System.out.println("Process has been terminated.");
      }
    }
    

After a process completes its task, it transitions to the Terminated state, freeing up resources for other processes.

Example: Process Preemption

This example demonstrates the transition from Running to Ready when a process is preempted by the scheduler.


    class ProcessPreemption {
      public static void main(String[] args) {
          System.out.println("Process has been preempted and moved back to ready state.");
      }
    }
    

Preemption occurs when a higher priority process needs CPU time, causing the current process to return to the Ready state.

logo of wikigalaxy

Newsletter

Subscribe to our newsletter for weekly updates and promotions.

Privacy Policy

 • 

Terms of Service

Copyright © WikiGalaxy 2025