What is Starvation and Aging?
In this blog, we will learn about the concept of Starvation that occurs generally in Priority Scheduling or in Shortest Job First Scheduling. We will see how Starvation is very bad for a process and how we can overcome this problem of Starvation with the help of Aging. So, let's get started.
Brief Overview of Priority Scheduling Algorithm
Before getting into the details of Starvation, let's have a quick overview of Priority Scheduling algorithms.
In Priority scheduling technique, we assign some priority to every process we have and based on that priority, the CPU will be allocated and the process will be executed. Here, the CPU will be allocated to the process that is having the highest priority. We don't care about the burst time here. Even if the burst time is low, the CPU will be allocated to the process having the highest priority. (You can learn more about Burst time from here )
In the above image, we can see the priority of process P1 is the highest, followed by P3 and P2. So, the CPU will be allocated to process P1, then to process P3 and then to process P2.
NOTE: In our example, we are taking 0 as the highest priority number and 100 or more as the lowest priority number. You can take the reverse of it also but the concept will be the same i.e. higher priority process will be allocated the CPU first.
Starvation
If you closely look at the concept of Priority scheduling, then you might have noticed one thing. What if the priority of some process is very low and the higher priority processes keep on coming and the CPU is allocated to that higher priority processes and the low priority process keeps on waiting for its turn. Let's have an example:
In the above example, the process P2 is having the highest priority and the process P1 is having the lowest priority. In general, we have a number of processes that are in the ready state for its execution. So, as time passes, if only that processes are coming in the CPU that are having a higher priority than the process P1, then the process P1 will keep on waiting for its turn for CPU allocation and it will never get CPU because all the other processes are having higher priority than P1. This is called Starvation.
Starvation is a phenomenon in which a process that is present in the ready state and has low priority, keeps on waiting for the CPU allocation because some other process with higher priority comes with due respect to time.
So, starvation should be removed because if some process is in the ready state then we should provide CPU to it. Since the process is of low priority so we can take our time for CPU allocation to that process but we must ensure that the CPU is allocated.
Aging
To avoid starvation, we use the concept of Aging. In Aging, after some fixed amount of time quantum, we increase the priority of the low priority processes. By doing so, as time passes, the lower priority process becomes a higher priority process.
For example, if a process P is having a priority number as 75 at 0 ms. Then after every 5 ms(you can use any time quantum), we can decrease the priority number of the process P by 1(here also instead of 1, you can take any other number). So, after 5 ms, the priority of the process P will be 74. Again after 5 ms, we will decrease the priority number of process P by 1. So, after 10 ms, the priority of the process P will become 73 and this process will continue. After a certain period of time, the process P will become a high priority process when the priority number comes closer to 0 and the process P will get the CPU for its execution. In this way, the lower priority process also gets the CPU. No doubt the CPU is allocated after a very long time but since the priority of the process is very low so, we are not that much concerned about the response time of the process(read more about response time from here ). The only thing that we are taking care of is starvation.
So, we are Aging our low priority process to make it a high priority process and as a result, to allocate the CPU for it.
Whenever you are using Priority scheduling algorithm or Shortest Job First algorithm, then make sure to use the concept of Aging, otherwise, your process will end up with starvation.
That's it for this blog. Hope you enjoyed this blog.
Do share this blog with your friends to spread the knowledge.
Keep Learning :)
Team AfterAcademy!