Process State in Operating System | Operating System EP - 05

Process State in Operating System | Operating System EP - 05

In this article, we will learn about the process state in the operating system. We will discuss many topics such as Long term scheduler, Medium-term scheduler, Short term scheduler, Pre-emptive, and Non Pre-emptive.

Process State:

process2.png

  • Before the New State there was no process, we had just created a process, or it may happen that when we open (switch on) our system many process get starts automatically.

  • When we initialize the process to start, first it gets stored in RAM and the process gets queued, and by this, now the process is in Ready State. Before initializing the process was in a New State in secondary memory.

Long term scheduler:

  • The main task of LTS( Long Term Scheduler ) is to send the maximum number of processes from New State (secondary memory) to Ready State (RAM) and it is done by using the concept of multiprogramming.

  • Now from RAM, the process will be transferred to CPU, which means from the Ready State to Running State. If we have one CPU then uni-processing will occur, while if we have multiple CPUs then parallel processing/ multiprocessing will occur. The process is still in RAM but now at a different location/ address and its state is also changed from the queue to executing.

  • When the process is completed then it is terminated and then dislocation will happen, that means in starting some resources in the form of (RAM) was allocated to that process, which will be taken back from it as we have a limited size of RAM. Now the state of that process is completed.

  • There is a scenario, suppose the CPU is executing a process and while the execution is going on another process with high priority came, so in that case the CPU will return the process to RAM and start executing the high priority process.

Short term scheduler:

  • There is a concept of Time-sharing this is the concept of multitasking. In this, the CPU will execute a process for a fixed time interval and if the process gets completed then it gets terminated, otherwise, it will send back that process to RAM and start executing another process for that time interval. This is done repeatedly due to which multitasking is achieved.

Non-Pre-emptive:

  • Non pre-emptive means that if the CPU executes a single process at a time from start to finish without starting another process in between, then it is considered as non-pre-emptive.

nonpreemtive.png

Pre-emptive:

  • When we stop a running process and start another process at its place due to a high priority process or if time quantum is achieved then this is considered as pre-emptive.

preemptive.png

  • There is another case if the CPU is running and the process demands I/O operation, so in this case, CPU can’t help the process so it sends the process to state which is known as wait/ block and CPU is another process. This is done because the CPU runs fast while the process wants to do some I/O operation, which will be done with the help of secondary memory and we know that secondary memory is slow. Hence the process gets shifted to another place in RAM because the CPU has stopped executing it. When the I/O request of the process is completed then it does not go to running state rather it goes to ready state and when that process chance will come CPU will start executing it.

Medium-term scheduler:

  • There is a worst-case scenario, in which suppose we have 10 processes and all of them want to perform I/O operation, so in that case, as the size of RAM is limited some process will be sent to suspend/ wait state which is in secondary memory, and these process will complete their I/O operation there, and once there I/O request is completed, they came back to wait/block state which is situated in RAM and from there it will be sent to ready state which is also in RAM.

mts.png

  • There is another case that supposes ready state is filled with process, then a process came to it which is VVIP and have very high priority, then, in that case, some process from the ready state will be sent to ready suspend state in order to make free space for VVIP process, and when there is space available in ready state the process came back to it.

mts2.png

  • There is another exception you can understand from the diagram below.

Process-State-Diagram.png

  • When the process has completed its I/O operation but it is not getting a chance to go back to the wait/block state because it is already filled, then it can also go to the suspend ready state and from there it can go to ready state which is the ultimate goal of the process.

Note: You can get info of all process from “Task Manager” in windows, “PS command” in Linux (process state command)

Now let us talk about each every process state:

  • New State: A process is said to be in a new state when a program present in the secondary memory is initiated for execution.
  • Ready State: A process moves from a new state to a ready state after it is loaded into the main memory and is ready for execution.

In the ready state, the process waits for its execution by the processor.

In a multiprogramming environment, many processes may be present in the ready state.

  • Running( Executing ) State: A process moves from the ready state to run state after it is assigned the CPU for execution.
  • Terminate State: A process moves from run state to terminate state after its execution is completed.

After entering the terminate state, the context (PCB) of the process is deleted by the operating system.

  • Block/Wait State: A process moves from run state to block or wait state if it requires an I/O operation or some blocked resource during its execution.

After the I/O operation gets completed or resource becomes available, the process moves to the ready state.

  • Suspend Ready State: A process moves from ready state to suspend ready state if a process with higher priority has to be executed but the main memory is full.

Moving a process with a lower priority from the ready state to suspend ready state creates a room for higher priority process in the ready state.

The process remains in the suspend ready state until the main memory becomes available.

When main memory becomes available, the process is brought back to the ready state.

  • Suspend Wait State: A process moves from wait/block state to suspend wait state if a process with higher priority has to be executed but the main memory is full.

Moving a process with a lower priority from wait state to suspend wait state creates a room for higher priority process in the wait/block state.

After the completion of IO operation, the process is moved to the wait/block state again.

But after completion of IO operation, there is no space in block/wait state this process will go to suspend ready state.