Prerequisite – CPU Scheduling, Process Management
Lottery Scheduling is type of process scheduling, somewhat different from other Scheduling. Processes are scheduled in a random manner. Lottery scheduling can be preemptive or non-preemptive. It also solves the problem of starvation. Giving each process at least one lottery ticket guarantees that it has non-zero probability of being selected at each scheduling operation.
In this scheduling every process have some tickets and scheduler picks a random ticket and process having that ticket is the winner and it is executed for a time slice and then another ticket is picked by the scheduler. These tickets represent the share of processes. A process having a higher number of tickets give it more chance to get chosen for execution.
Example – If we have two processes A and B having 60 and 40 tickets respectively out of total 100 tickets. CPU share of A is 60% and that of B is 40%.These shares are calculated probabilistically and not deterministically.
- We have two processes A and B. A has 60 tickets (ticket number 1 to 60) and B have 40 tickets (ticket no. 61 to 100).
- Scheduler picks a random number from 1 to 100. If the picked no. is from 1 to 60 then A is executed otherwise B is executed.
- An example of 10 tickets picked by Scheduler may look like this –
Ticket number - 73 82 23 45 32 87 49 39 12 09. Resulting Schedule - B B A A A B A A A A.
- A is executed 7 times and B is executed 3 times. As you can see that A takes 70% of CPU and B takes 30% which is not the same as what we need as we need A to have 60% of CPU and B should have 40% of CPU.This happens because shares are calculated probabilistically but in a long run(i.e when no. of tickets picked is more than 100 or 1000) we can achieve a share percentage of approx. 60 and 40 for A and B respectively.
Ways to manipulate tickets –
- Ticket Currency –
Scheduler give a certain number of tickets to different users in a currency and users can give it to there processes in a different currency. E.g. Two users A and B are given 100 and 200 tickets respectively. User A is running two process and give 50 tickets to each in A’s own currency. B is running 1 process and gives it all 200 tickets in B’s currency. Now at the time of scheduling tickets of each process are converted into global currency i.e A’s process will have 50 tickets each and B’s process will have 200 tickets and scheduling is done on this basis.
- Transfer Tickets –
A process can pass its tickets to another process.
- Ticket inflation –
With this technique a process can temporarily raise or lower the number of tickets it own.
This article is contributed by Ashish Sharma. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- Operating System | Process Management | CPU Scheduling
- Operating System | Process Table and Process Control Block (PCB)
- Operating System | Multilevel Queue Scheduling
- Operating System | Multiple-Processor Scheduling
- Operating System | Selfish Round Robin Scheduling
- Operating System | Priority Scheduling with different arrival time - Set 2
- Operating System | Multilevel Feedback Queue Scheduling
- Operating System | Shortest Job First scheduling with predicted burst time
- Operating System | Highest Response Ratio Next (HRRN) Scheduling
- Operating System | Process Synchronization | Set 2
- Operating System | Process Scheduler
- Operating System | Process Synchronization | Introduction
- Operating System | Process Management | Introduction
- Operating System | Process Management | Deadlock Introduction
- Operating System | Process-based and Thread-based Multitasking
Improved By : dk619