
- OS - Home
- OS - Needs
- OS - Overview
- OS - History
- OS - Components
- OS - Structure
- OS - Architecture
- OS - Services
- OS - Properties
- OS - TAT & WAT
- OS Processes
- OS - Processes
- OS - Process Scheduling
- OS - Scheduling Algorithms
- FCFS Scheduling Algorithm
- SJF Scheduling Algorithm
- Round Robin Scheduling Algorithms
- HRRN Scheduling Algorithms
- Priority Scheduling Algorithms
- Multilevel Queue Scheduling
- Context Switching
- Operations on Processes
- Lottery Process Scheduling
- Predicting Burst Time SJF Scheduling
- Race Condition Vulnerability
- Critical Section Synchronization
- Mutual Exclusion Synchronization
- Process Control Block
- Inter Process Communication
- Preemptive and Non-Preemptive Scheduling
- Operating System - Deadlock
- Introduction to Deadlock in Operating System
- Conditions for Deadlock in Operating System
- OS Synchronization
- Operating System - Process Synchronization
- Operating System - Critical Section
- Operating System - Semaphores
- Operating System - Counting Semaphores
- Operating System - Mutex
- Operating System - Lock Variable in Process Synchronization
- Operating System - Turn Variable in Process Synchronization
- Operating System - Bounded Buffer Problem
- Operating System - Reader Writer Locks in Process Synchronization
- Operating System - Test Set Lock in Process Synchronization
- Operating System - Peterson Solution in Process Synchronization
- Operating System - Monitors in Process Synchronization
- Operating System - Sleep and Wake in Process Synchronization
- OS Memory Management
- OS - Memory Management
- OS - Virtual Memory
- OS Storage Management
- File Systems in Operating System
- Linked Index Allocation in Operating System
- Indexed Allocation in Operating System
- Structures of Directory in Operating System
- File Attributes in Operating System
- Operating System - Page Replacement
- Operating Systems - Thrashing
- Belady’s Anomaly in Page Replacement Algorithms
- Optimal Page Replacement Algorithm
- Operating System - Types
- Types of Operating System
- Batch Processing Operating System
- Multiprocessing Operating System
- Hybrid Operating System
- Monolithic Operating System
- Zephyr Operating System
- Nix Operating System
- Blackberry Operating System
- Garuda Operating System
- Tails Operating System
- Clustered Operating System
- Haiku Operating System
- AIX Operating System
- Solus Operating system
- Tizen Operating System
- Bharat Operating System
- Fire Operating System
- Bliss Operating System
- VxWorks Operating System
- Embedded Operating System
- Single User Operating System
- OS Miscellaneous
- OS - Multi-threading
- OS - I/O Hardware
- OS - I/O Software
- OS - Security
- OS - Linux
- OS Useful Resources
- OS - Quick Guide
- OS - Useful Resources
- OS - Discussion
Operating System - Lottery Process Scheduling
In a multiprogramming environment, CPU scheduling algorithms are strategies that decide which process in the ready queue should execute next. Unlike the conventional scheduling algorithms that try to optimize the turnaround time or waiting time, lottery process scheduling aims to give each process a certain percentage of CPU time.
What is Lottery Process Scheduling?
Lottery process scheduling follows a probabilistic scheduling approach. The scheduler distributes tickets to the processes in the system which are allotted CPU time through lottery. The tickets may or may not be distributed uniformly. If a process possesses more tickets, it has a relatively higher probability of selection. Thus a process with more tickets has higher priority. In order to give equal priorities to all the processes, the scheduler distributes equal number of tickets to them.
This scheduling is also referred as a proportional-share scheduling and fair-share scheduling.
Working Principle of Lottery Process Scheduling
Lottery process scheduling has the following steps of implementation −
- Ticket Distribution − Initially, each process in the system is assigned some number of lottery tickets. Each ticket has a unique number and the total number of tickets distributed in the system is always the same.
- Lottery − The scheduler conducts lottery by drawing a random ticket. Generally, a random number generator is used that generates one ticket number among all the ticket numbers distributed in the system.
- Scheduling and Execution − The process having the winning ticket number is selected for execution in the next time slot. The selected process either runs to completion or to the end of the time slot whichever is smaller. If no process possesses the winning ticket, the lottery is done again.
- Ticket Adjustment − After all the processes which were allotted the tickets have run into completion, the scheduler wraps ups the present execution. If new processes arrive in the system, the scheduler restarts the procedure all over.
Manipulating tickets in 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 behaviour. 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.
Example of Lottery Process Scheduling
Let us consider a situation where there are three processes, P0, P1 and P2 and the scheduler have distributed a total of 100 lottery tickets to them, as shown in the first two columns of the following table −
Process | Lottery Ticket Numbers |
Proportion of Tickets $\mathrm{= \: \frac{No. \: of \: Tickets \: Allotted}{Total \: No. \: of \: Tickets} \: \times \: 100}$ |
---|---|---|
P0 | 0-10, 41-50 | 20/100 = 20% |
P1 | 11-40 | 30/100 = 30% |
P2 | 51-60 | 50/100 = 50% |
In the third column, we have calculated the proportion of tickets allotted to each process.
Consider that the lottery scheduler generates the following ticket numbers for the first 25 draws −
12, 34, 78, 55, 01, 23, 44, 54, 64, 94, 29, 89, 05, 36, 76, 62, 22, 32, 42, 51, 73, 85, 18, 81, 25
The resulting schedule will be −
P0, P1, P2, P2, P0, P1, P0, P2, P2, P2, P1, P2, P0, P1, P2, P2, P1, P1, P0, P2, P2, P2, P1, P2, P1
The percentage share of a process is calculated as −
$$\mathrm{ProportionalShare_{PX} \: = \: \frac{No. \: of \: Winning \: Draws \: by \: PX}{Total \: Number \: of \: Draws} \: \times \: 100}$$
Using this formula, we get the proportional share of each process as −
$$\mathrm{ProportionalShare_{P0} \: = \: \frac{5}{25} \: \times \: 100 \: = \: 20 \%}$$
$$\mathrm{ProportionalShare_{P1} \: = \: \frac{8}{25} \: \times \: 100 \: = \: 32 \%}$$
$$\mathrm{ProportionalShare_{P2} \: = \: \frac{12}{25} \: \times \: 100 \: = \: 48 \%}$$
We can observe that the proportional shares of CPU time of the processes are quite near to the proportion of tickets allotted to them. The values reach near perfection as the number of draws increases.
Advantages of Lottery Process Scheduling
- Lottery process scheduling is a fair scheduling algorithm. Each process has a probability of getting CPU time.
- As each process has a possibility of being selected, starvation is effectively avoided by this approach.
- It is adaptive to different operating system environments. It works well in real-time systems multi-processor systems etc.
- By using various distribution mechanisms, the method can be adjusted dynamically for various system requirements like assigning priorities etc.
- It can be implemented easily since we dont need to go through elaborate procedure to predict the burst times of processes.
Disadvantages of Lottery Process Scheduling
- Lottery process scheduling has an additional overhead of assigning lottery tickets to processes and also drawing lottery.
- The performance depends upon the random number generator. If the generator is biased or generates repetitive numbers, the scheduling fails. On the other side, a good generator requires more CPU time and other resources.
- It is more complex than First Come First Serve or Round Robin Scheduling due to its dependency on random number generator.