Starvation and Aging in Operating Systems
Generally, Starvation occurs in Priority Scheduling or Shortest Job First Scheduling. In the 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 has the highest priority. Even if the burst time is low, the CPU will be allocated to the highest priority process.
Starvation is very bad for a process in an operating system, but we can overcome this starvation problem with the help of Aging.
What is Starvation?
Starvation or indefinite blocking is a phenomenon associated with the Priority scheduling algorithms. A process that is present in the ready state and has low priority keeps waiting for the CPU allocation because some other process with higher priority comes with due respect time. Higher-priority processes can prevent a low-priority process from getting the CPU.
For example, the above image process has higher priority than other processes getting CPU earlier. We can think of a scenario in which only one process has very low priority (for example, 127), and we are giving other processes high priority. This can lead to indefinitely waiting for the process for CPU, which is having low-priority, which leads to Starvation.
Causes of Starvation
Some of the common causes of Starvation in the operating system are as follows:
- When Starvation occurs, there are not enough resources to go around, and the priority of the processes starts becoming low.
- A lower priority process may wait forever if higher priority processes constantly monopolize the processor.Since the low priority programs are not interacting with anything, it becomes impossible for Starvation to cause a deadlock.
- If a random selection of processes is used, then a process may wait for a long time because of non-selection.
- Starvation is a fail-safe method to get out of a deadlock, making it much more important how it affects the system as a whole.
- If a process is never provided the resources, it is required for execution because of faulty resource allocation decisions, and Starvation can occur.
- Starvation may occur if there are not enough resources to provide to every process as required.
Solutions to Handle Starvation
Some solutions that can be implemented in a system to handle Starvation are as follows:
- An independent manager can be used for the allocation of resources. This resource manager distributes resources fairly and tries to avoid Starvation.
- Random selection of processes for resource allocation or processor allocation should be avoided as they encourage Starvation.
- The priority scheme of resource allocation should include concepts such as Aging, where the priority of a process is increased the longer it waits, which avoids Starvation.
Differences between Starvation and Deadlock
Below are some differences between deadlock and Starvation in an operating system, such as:
- Deadlock occurs when none of the processes in the set can move ahead due to occupancy of the required resources by some other process, as shown in the image below. On the other hand, Starvation occurs when a process waits for an indefinite time to get the resource it requires.
- Another name of deadlock is Circular Waiting. And another name of Starvation is Lived lock.
- No process can progress when a deadlock occurs, while in Starvation, other processes can progress or proceed apart from the victim process.
What is Aging in OS?
In Operating systems, Aging is a scheduling technique used to avoid Starvation. Fixed priority scheduling is a scheduling discipline in which tasks queued for utilizing a system resource is assigned each priority. A task with a high priority is allowed to access a specific system resource before a task with a lower priority is allowed to do the same.
Aging is a technique of gradually increasing the priority (by time quantum) of processes that wait in the system for a long time. By doing so, as time passes, the lower priority process becomes a higher priority process.
A disadvantage of this approach is that tasks assigned with a lower priority may be starved when many high priority tasks are queued. Aging is used to gradually increase the priority of a task based on its waiting time in the ready queue.
Problem
In priority-based scheduling algorithms, a major problem is an indefinite block or Starvation. A process that is ready to run but waiting for the CPU can be considered blocked. A priority scheduling algorithm can leave some low-priority processes waiting indefinitely. A steady stream of higher-priority processes can prevent a low-priority process from ever getting the CPU.
Examples of Aging
Suppose a system with a priority range of 0-512. In this system, 0 means highest priority.
- Increasing Process
If priority ranges from 127(low) to 0(high), we could increase the priority of a waiting process by 1 Every 15 minutes. Eventually, even a process with an initial priority of 127 would take no more than 32 hours for the priority 127 processes to age to a priority-0 process. - Decreasing Process
If a process P has a priority number as 127 at 0 minutes, then after every 15 minutes (time quantum), decreasing the priority number of the process P by 1. So, after 15 m, the priority of the process P will be 126. Again after 15 m, decreasing the priority number of process P by 1. So, after 30 m, the priority of the process P will become 125, and this process will continue. Process P will become a high priority process when the priority number comes closer to 0, and process P will get the CPU for its execution after a very long time.
Uses of Aging
Aging is used to ensure that jobs with lower priority will eventually complete their execution. This technique can be used to reduce the Starvation of low priority tasks. There are many ways to implement Aging, but all have the same principle that the priority of a process should increase as it waits in the ready queue. The increase in priority may or may not be equal to the waiting time of the process.