Operating System - Starvation and Aging



In operating systems, starvation and aging are two important concepts related to process scheduling and resource allocation. Starvation is a situation where a process is denied access to resources it needs for execution, and aging is a technique used to prevent starvation. In this chapter, we will discuss both concepts in detail.

Starvation in Operating System

Starvation is a situation in which a process is not able to gain access to the resources it needs for execution. This happens when CPU scheduling algorithm prefers other higher priority processes over the lower priority ones. As a result, some processes may need to wait indefinitely while other processes are being executed. Starvation is also known as indefinite blocking.

Example of Starvation

Consider a system that uses priority scheduling for CPU allocation. In this system, processes with higher priority are executed first. For example, assume that there are three processes P1, P2, and P3 with priorities 3, 2, and 1 respectively (higher number indicates higher priority). Following is the sequence of events −

Process  Priority
P1       3 (high priority)
P2       2
P3       1

Process arrives in the order:
P1, P2, P3, P2, P1, P2, P2, P1, P3, P1, P2, ...

CPU allocation based on priority:
P1 -> P2 -> P2 -> P1 -> P2 -> P2 -> P2 -> P1 -> P1 -> P2 -> ...

Result: P3 never gets executed 

In this example, P3 got starved because it has the lowest priority. As long as there are higher priority processes (P1 and P2) in the queue, P3 will never get a chance to execute.

Causes of Starvation

The main causes of starvation in operating systems are −

  • Priority Scheduling − In priority scheduling algorithms, processes with higher priority are executed first. If there are always higher priority processes in the queue, lower priority processes may never get executed.
  • Resource Allocation − If resources are allocated in a way that some processes are always denied access to the resources they need, those processes may starve.
  • Deadlock − In some cases, deadlock can lead to starvation of multiple processes.

Aging in Operating System

Aging is a technique used to prevent starvation in operating systems. The idea behind aging is to gradually increase the priority of a process that are waiting in the queue for a long time. This way, even lower priority processes will eventually get a chance to execute.

Example of Aging

Continuing from the previous example, let's apply aging to the processes. Assume that for every time unit a process waits in the queue, its priority is increased by 1. The updated priorities of the processes after some time would be −

Process arrives in the order:
P1, P2, P3, P2, P1, P2, P2, P1, P3, P1, P2, ...

CPU allocation based on priority with aging:
Allocation                           Priority Now
-> Allocate P1 (priority 3)          {P1: 3, P2: 2, P3: 1}
-> Allocate P2 (priority 2)          {P1: 3, P2: 3, P3: 2}
-> Allocate P3 (priority 3)          {P1: 3, P2: 3, P3: 3}

Result: No starvation, all processes get executed

In this example, after applying aging, P3's priority eventually increased to match that of P1 and P2. As a result, P3 got a chance to execute.

Conclusion

Starvation is a situation where a process is waiting for infinite time due to resource allocation policies. To prevent starvation, operating systems use aging technique, here the priority of waiting processes is gradually increased over time. Meaning the older processes will have high priority over time. This ensures that all processes eventually get a chance to execute.

Advertisements