# Lottery Process Scheduling in Operating System

## Introduction

Lottery scheduling is a process scheduling algorithm used in operating systems that assign processes a fixed number of "lottery tickets" based on their priority, determining their likelihood of execution. In this article, we will talk about the lottery process scheduling algorithm, and how can manipulate tickets using the same.

## The Lottery Process Scheduling Algorithm

The higher the priority of a process, the more tickets the lottery process scheduling algorithm receives. In this algorithm, the scheduler chooses a ticket at random from the pool of available tickets. For execution, this algorithm chooses the process that owns the winning ticket.

The lottery scheduling algorithm is probabilistic. In this, the likelihood of a process being selected for execution is proportional to the number of tickets it contains. This is because each process has a chance of being selected regardless of its priority. This, in turn, allows for a more equitable distribution of resources among processes.

The operating system keeps track of all processes that are currently awaiting execution to enable lottery scheduling. Each process is assigned a certain number of tickets based on its priority. For instance, a process with a higher priority may be assigned 100 tickets. On the other hand, a process with a lower priority may be assigned only 10 tickets.

When it's time to start a new process, the lottery scheduler chooses a ticket at random from the pool of available tickets. The process of winning a ticket is chosen for execution, and its ticket count is reduced by one. The process is then executed for a specific time slice before being returned to the pool of available processes.

The operating system keeps track of all processes that are currently awaiting execution in order to enable lottery scheduling. Each process is assigned a number of tickets based on its priority. A higher priority process, for example, may be assigned 100 tickets, whereas a lower priority process may be assigned only 10 tickets.

## Lottery Scheduling algorithm as a probabilistic algorithm

The lottery scheduling algorithm is a probabilistic algorithm. This means that the likelihood of a process being selected for execution is proportional to the number of tickets it contains. This is because each process has a chance of being selected regardless of priority. This further, allows for a more equitable distribution of resources among processes.

When a new process is initiated, the lottery scheduler selects a ticket at random from the pool of available tickets. The winning process is chosen for execution, and its ticket count is reduced by one. The process is then run for a set amount before being returned to the pool of available processes.

## Manipulating tickets in the Lottery Process Scheduling algorithm

The lottery tickets are typically manipulated based on the priority of each process. Higher-priority processes are assigned more tickets than lower-priority processes, increasing their chances of being selected for execution. However, there are a few different ways to manipulate tickets in lottery scheduling −

• Static Distribution − The number of tickets assigned to each process in this method is fixed and does not change over time. For instance, a process with a higher priority may be assigned 100 tickets. On the other hand, a process with a lower priority may be assigned only 10 tickets. This method is simple to implement, but it may not result in the most efficient or equitable resource distribution.

• Dynamic Distribution − In this method, the total amount of tickets allocated to each process may fluctuate over time according to the system's behavior. For example, if a strong-priority process is taking up materials and starving other operations, its ticket count may be minimized to give other procedures an increased likelihood of being selected. Although this technique has a greater computation overhead, it may result in more effective and equal resource allocation.

• Weighted Distribution − In this method, the total amount of tickets designated to each process is determined by factors other than its priority. Other factors, which include the quantity of processing power it has already consumed, also play a role. Despite having the same priority, an operation that consumed a lot of processing power may be allocated a lesser number of tickets than a procedure that has employed very little CPU time. This approach can be difficult to put in place, but it can help prevent processes from monopolizing resources.

## Conclusion

Lottery scheduling is an effective algorithm for process scheduling in operating systems. This is especially effective when a fair distribution of resources is required. In this article, we explored this article in detail along with its probabilistic nature and also, how we can manipulate tickets using this algorithm.

Updated on: 04-May-2023

558 Views