Do you think IIT Guwahati certified course can help you in your career?
No
Introduction
When a program runs on the CPU, from start to finish, the procedure goes through a number of stages. The States of a process that is executed by the Process include whether the process has been completed or is waiting for some I/O operation from the user, as well as if the process is waiting for the CPU to begin with the execution.
So, In this article, we will learn about the states of a process in detail and how and when a process needs to enter such states.
Before we start with the different types of states a process undergoes, let us look at what exactly is the process:
A Process is something that is currently in execution in the Operating System. As a result, an active program is referred to as a Process. When you want to search for something from the web, for example, you typed Coding Ninjas, now this could be a process. Another example of a process is turning on your music player and listening to some soothing music.
In contrast to the program, which is regarded as a 'passive' entity, a process is an 'active' entity.
A process is essentially a program in operation or in order words, a program under execution is a process.
Process = Program + runtime activity
Here, the Program can be the code or set of instructions, and runtime activity can be the operands and other information.
The execution of a process must be done in a specific order. To put it another way, we write our computer programs in a text file, and when we run them, they turn into a process that completes all of the tasks specified in the program.
A program can be separated into four pieces when it is put into memory and becomes a process: stack, heap, code or text section, and data section. This is also known as the Representation/Implementation of a process.
Each process in the memory will have the above four sections.
Furthermore, a Process is defined by a number of attributes. The following are some of the attributes of a Process:
Process Id: Every process will be assigned a Process Id that will allow it to be distinguished from other processes.
Process state: At any given point in time, every process has certain states connected with it. And this is signified by the process state. It could be running, ready, or waiting which we’ll discuss later in this article.
CPU scheduling information: CPU scheduling algorithms such as SJN, FCSF, Round-Robin, SJF, and others are used to execute each process.
I/O information: I/O devices are required for the execution of each process. As a result, it's critical to have information about the devices that have been assigned to you and the devices that you require.
States of a Process
As we have already discussed what precisely is the process in systems, now we need to understand how a process changes the states during the time of execution. The state of a process is defined in part by the current activity of that process. Here we will discuss every stage of a process in detail.
As we understand that there are many processes that are running at a time, this is not truly the case. At any given time, a processor can only execute one Process. There are the different Process States that determine which Process will be executed next. The Processor will use the States of the Processes to execute all of the processes.
Note: A process must go through a minimum of four states to be considered complete. The new state, ready state, run state, and terminated state are the four states. However, if a process also requires I/O, the minimum number of states required is five.
A process goes through several phases during its execution. As a result, in this area of the article, we'll learn about the numerous stages of a process lifecycle.
New State: In this phase, the process is about to be formed but has not yet been created; instead, the OS will use the program in secondary memory to build the process. When a process is first created, it is in a New state. It is the beginning of a process.
Ready State: After a process is created, it enters the ready state, which means it gets loaded into the main memory(RAM). The process is ready to execute and is awaiting CPU time to complete its task. Processes that are ready to be executed by the CPU are kept in a ready process queue. The process is waiting for the short-term scheduler to allocate it a processor so it may execute. This stage occurs shortly following the process's new state.
Ready Suspended State: There can be several processes in the ready state, however, due to memory constraints, if the memory is full, one of the processes in the ready state will be moved to the ready suspended state. The processes in the ready suspended state are all in secondary memory. The process will switch back to the ready state whenever the process is once again brought onto the main memory.
Running State: Using a CPU scheduling method, the CPU selects one process among the ones that are in the ready condition. The process is now in the running state and will be performed by the CPU. If the system has n processors, we can have n processes executing at the same time.
Waiting or Blocked State: During the execution of the process, it may be necessary to do certain I/O operations, such as writing to a file, or a higher priority process may appear. In such cases, the process will be forced to enter a waiting or blocked state until the other process completes its task. As a result, the process is in a state of waiting for something. When the event is finished, the process returns to the ready state.
Waiting Suspended State: When the system's waiting queue becomes full, some processes are sent to the waiting suspended state.
Terminated State: When a process' execution is finished, it moves from the running state to the terminated state. The operating system deletes the process's context and removes it from the main memory once it enters the terminate state.
Now, to understand the flow of the process from the beginning as a new state to the terminated state, refer to the below figure:
As we can see in the figure above,
When a process is formed, it begins in a new state. It enters the ready state after the new state.
The process will be switched to the ready suspended state if the ready queue is full.
The CPU will select a process from the ready state, and the process will be performed by the CPU and placed in the running state.
During the process execution, it's possible that certain I/O operations will be required. As a result, it must enter the waiting state, and if the waiting state is full, it will be transferred to the suspended waiting state.
After conducting I/O operations, the process might go from the waiting state to the ready state.
The procedure may transition from the waiting suspended state to the waiting or ready suspended state.
Finally, when the process has completed its execution, the process will be terminated, and the process's data will be erased.
To get more clarity about which state is in which memory, we can see the below figure.
State
Present in Memory
New state
Secondary Memory
Ready state
Main Memory
Ready Suspended state
Secondary Memory
Running state
Main Memory
Waiting / Blocked state
Main Memory
Waiting Suspended state
Secondary Memory
Terminated state
–
Note: It is preferable to move a process from the wait state to the suspend wait state.
Let’s consider the situation when a high-priority process arrives and the main memory is already full. Then there are two ways to make space for it.
These are the two possibilities:
Suspending a process that has a lesser priority from the ready state.
Transferring a lower-priority process from the wait state to the suspend state.
Among these-
It is preferable to move a process from the wait state to the suspended wait state. This is because the process is already waiting on a resource that is currently unavailable.
Why are the processes being transferred from ready state to ready suspended state?
The processes that are in a ready suspended state are stored in the secondary memory. They were originally stored in the ready state in the main memory, but due to the lack of memory, they were forced to be suspended and stored in secondary memory.
How many processes are allowed to run at the same time?
If the CPU is working with a single processor, you can only run a single process at a time. To process many processes simultaneously, there should be processors equal in number to the processes present in the environment.
What is a PCB, and How does it contribute to the whole process?
Every process has a Process Control Block, which is a data structure managed by the Operating System. A PCB stores all of the information required to keep track of a process. It is very essential for process management as the data structuring for the processes is done in terms of the PCB. It also identifies the current state of the operating system.
Conclusion
To summarize the article, we learned how a process is created and how it is sent to the different states to make sure the operating system is working efficiently. We learned how a process survives various states and later after being killed by the termination process. We also have a brief understanding of which state is processed in what type of memory( Main or Secondary). But the knowledge never stops, so in order to gain a better understanding of the operating system, you can go through many articles on our platform.