logo

Programma voor Round Robin-planning voor dezelfde aankomsttijd

Ronde Robin is een CPU-planningsalgoritme waarbij aan elk proces cyclisch een vast tijdslot wordt toegewezen. Het is de preventieve versie van het First come First Serve CPU Scheduling-algoritme.

abstracte klasse Java
  • Het Round Robin CPU-algoritme richt zich over het algemeen op de Time Sharing-techniek.
  • De tijdsperiode gedurende welke een proces of taak preventief mag worden uitgevoerd, wordt tijd genoemd quantum .
  • Aan elk proces of elke taak in de wachtrij wordt de CPU voor die tijd toegewezen. Als de uitvoering van het proces gedurende die tijd is voltooid, zal het proces dat doen. einde anders gaat het proces terug naar de wachttafel en wacht op de volgende beurt om de uitvoering te voltooien.

Kenmerken van het Round Robin CPU-planningsalgoritme

  • Het is eenvoudig, gemakkelijk te implementeren en zonder honger, omdat alle processen een behoorlijk deel van de CPU krijgen.
  • Eén van de meest gebruikte technieken in CPU-planning is een kern.
  • Het is preventief omdat aan processen maximaal een vaste tijdsduur een CPU wordt toegewezen.
  • Het nadeel ervan is dat er meer overhead is bij het wisselen van context.

Voordelen van het Round Robin CPU-planningsalgoritme

  • Er is sprake van eerlijkheid, aangezien elk proces een gelijk deel van de CPU krijgt.
  • Het nieuw gemaakte proces wordt aan het einde van de gereedstaande wachtrij toegevoegd.
  • Een round-robin-planner maakt doorgaans gebruik van time-sharing, waarbij elke taak een tijdslot of kwantum wordt gegeven.
  • Bij het uitvoeren van een round-robin-planning wordt een bepaald tijdkwantum toegewezen aan verschillende taken.
  • Elk proces krijgt in deze planning de kans om na een bepaalde kwantumtijd opnieuw te plannen.

Nadelen van het Round Robin CPU-planningsalgoritme

  • Er is een grotere wachttijd en responstijd.
  • Er is een lage doorvoer.
  • Er zijn contextschakelaars.
  • Het Gantt-diagram lijkt te groot te zijn (als de kwantumtijd korter is voor planning. Bijvoorbeeld: 1 ms voor grote planning.)
  • Tijdrovende planning voor kleine kwantum.

Voorbeelden om de werking te laten zien Ronde Robin Planningsalgoritme

Voorbeeld 1: Beschouw de volgende tabel met aankomsttijden en burst-tijden voor vier processen P1, P2, P3 en P4 en gegeven Tijdkwantum = 2

Proces Burst-tijd Aankomsttijd
P1 5 ms 0 ms
P2 4 ms 1 ms
P3 2 ms 2 ms
P4 1 ms 4 ms

Het Round Robin CPU-planningsalgoritme werkt op basis van de onderstaande stappen:



Op tijd = 0,

  • De uitvoering begint met proces P1, dat burst-tijd 5 heeft.
  • Hier wordt elk proces gedurende 2 milliseconden uitgevoerd ( Tijd Kwantumperiode ). P2 en P3 staan ​​nog in de wachtrij.
Tijdinstantie Proces Aankomsttijd Klaar wachtrij Lopende wachtrij Uitvoertijd Initiële bursttijd Resterende uitbarsting
Tijd
0-2 ms P1 0 ms P2, P3 P1 2ms 5ms 3ms

Op tijd = 2,

  • De processen P1 en P3 arriveren in de gereedwachtrij en P2 begint met de uitvoering ervan TQ periode
Tijdinstantie Proces Aankomsttijd Klaar wachtrij Lopende wachtrij Uitvoertijd Initiële bursttijd Resterende uitbarsting
Tijd
2-4 ms P1 0 ms P3, P1 P2 0 ms 3ms 3ms
P2 1 ms 2ms 4ms 2ms

Op tijd = 4,

  • Het proces P4 arriveert in de klaar wachtrij ,
  • Vervolgens wordt P3 uitgevoerd voor TQ periode.
Tijdinstantie Proces Aankomsttijd Klaar wachtrij Lopende wachtrij Uitvoertijd Initiële bursttijd Resterende uitbarsting
Tijd
4-6 ms P1 0 ms P1, P4, P2 P3 0 ms 3ms 3ms
P2 1 ms 0 ms 2ms 2ms
P3 2ms 2ms 2ms 0 ms

Op tijd = 6,

  • Proces P3 voltooit de uitvoering ervan
  • Proces P1 wordt uitgevoerd voor TQ periode zoals deze de volgende is in de b.
Tijdinstantie Proces Aankomsttijd Klaar wachtrij Lopende wachtrij Uitvoertijd Initiële bursttijd Resterende uitbarsting
Tijd
6-8 ms P1 0 ms P4, P2 P1 2ms 3ms 1 ms
P2 1ms 0 ms 2ms 2ms

Op tijd = 8,

  • Proces P4 begint met uitvoeren, maar zal niet worden uitgevoerd Tijd Kwantumperiode omdat het een burst-tijd = 1 heeft
  • Daarom wordt het slechts 1 ms uitgevoerd.
Tijdinstantie Proces Aankomsttijd Klaar wachtrij Lopende wachtrij Uitvoertijd Initiële bursttijd Resterende uitbarsting
Tijd
8-9 ms P1 0 ms P2, P1 P4 0 ms 3ms 1ms
P2 1 ms 0 ms 2ms 2ms
P4 4ms 1ms 1 ms 0 ms

Op tijd = 9,

  • Proces P4 voltooit de uitvoering ervan
  • Proces P2 begint te worden uitgevoerd TQ periode zoals deze de volgende is in de klaar wachtrij
Tijdinstantie Proces Aankomsttijd Klaar wachtrij Lopende wachtrij Uitvoertijd Initiële bursttijd Resterende uitbarsting
Tijd
9-11 ms P1 0 ms P1 P2 0 ms 3ms 1 ms
P2 1 ms 2ms 2ms 0 ms

Op tijd = 11,

  • Proces P2 voltooit de uitvoering ervan.
  • Proces P1 wordt uitgevoerd en duurt slechts 1 ms
Tijdinstantie Proces Aankomsttijd Klaar wachtrij Lopende wachtrij Uitvoertijd Initiële bursttijd Resterende uitbarsting
Tijd
11-12 ms P1 0 ms P1 1 ms 1ms 0 ms

Op tijd = 12,

  • Proces P1 voltooit de uitvoering ervan.
  • De algehele uitvoering van de processen zal zijn zoals hieronder weergegeven:
Tijdinstantie Proces Aankomsttijd Klaar wachtrij Lopende wachtrij Uitvoertijd Initiële bursttijd Resterende uitbarsting
Tijd
0-2 ms P1 0 ms P2, P3 P1 2ms 5ms 3ms
2-4 ms P1 0 ms P3, P1 P2 0 ms 3ms 3ms
P2 1ms 2ms 4ms 2ms
4-6 ms P1 0 ms P1, P4, P2 P3 0 ms 3ms 3ms
P2 1 ms 0 ms 2ms 2ms
P3 2ms 2ms 2ms 0 ms
6-8 ms P1 0 ms P4, P2 P1 2ms 3ms 1ms
P2 1ms 0 ms 2ms 2ms
8-9 ms P1 0 ms P2, P1 P4 0 ms 3ms 1 ms
P2 1ms 0 ms 2ms 2ms
P4 4ms 1 ms 1ms 0 ms
9-11 ms P1 0 ms P1 P2 0 ms 3ms 1 ms
P2 1ms 2ms 2ms 0 ms
11-12 ms P1 0 ms P1 1 ms 1 ms 0 ms

Gantt-diagram zal als volgt zijn:

Gantt-diagram voor Round Robin-planningsalgoritme

Gantt-diagram voor Round Robin-planningsalgoritme

Hoe bereken je onderstaande tijden in Round Robin met behulp van een programma?

  • Doorlooptijd: Tijd waarop het proces de uitvoering voltooit.
  • Draai rond tijd: Tijdsverschil tussen voltooiingstijd en aankomsttijd. Turn Around Time = Voltooiingstijd – Aankomsttijd
  • Wachttijd (WT): Tijdsverschil tussen de omlooptijd en de burst-tijd.
    Wachttijd = Doorlooptijd – Bursttijd

Laten we nu het gemiddelde berekenen wachttijd en draai je om tijd:

Processen BIJ BT CT TAT GEW
P1 0 5 12 12-0 = 12 12-5 = 7
P2 1 4 elf 11-1 = 10 10-4 = 6
P3 2 2 6 6-2 = 4 4-2 = 2
P4 4 1 9 9-4 = 5 5-1 = 4

Nu,

  • Gemiddelde doorlooptijd = (12 + 10 + 4 + 5)/4 = 31/4 = 7,7
  • Gemiddelde wachttijd = (7 + 6 + 2 + 4)/4 = 19/4 = 4,7

Voorbeeld 2: Beschouw de volgende tabel met aankomsttijden en burst-tijden voor drie processen P1, P2 en P3 en gegeven Tijdkwantum = 2

Proces Burst-tijd Aankomsttijd
P1 10 ms 0 ms
P2 5 ms 0 ms
P3 8 ms 0 ms

Op dezelfde manier, Gantt-diagram voor dit voorbeeld:

Gantt-diagram bijvoorbeeld 2

Gantt-diagram bijvoorbeeld 2

Laten we nu het gemiddelde berekenen wachttijd en draai je om tijd:

Processen BIJ BT CT TAT GEW
P1 0 10 23 23-0 = 23 23-10 = 13
P2 0 5 vijftien 15-0 = 15 15-5 = 10
P3 0 8 eenentwintig 21-0 = 21 21-8 = 13

Totale doorlooptijd = 59 ms
Dus, Gemiddelde doorlooptijd = 59/3 = 19,667 ms

En de totale wachttijd = 36 ms
Dus, Gemiddelde wachttijd = 36/3 = 12,00 ms

Programma voor Round Robin Scheduling met aankomsttijd op 0 voor alle processen

Stappen om wachttijden van alle processen te vinden

  • Maak een array rem_bt[] om de resterende burst-tijd van processen bij te houden. Deze array is in eerste instantie een kopie van bt[] (burst times array)
  • Maak nog een array wt[] om wachttijden van processen op te slaan. Initialiseer deze array als 0.
  • Initialiseer tijd: t = 0
  • Blijf alle processen doorlopen terwijl ze nog niet zijn voltooid. Doe het volgende voor ik ben proces als dit nog niet is gebeurd.
    • Als rem_bt[i]> kwantum
      • t = t + kwantum
      • rem_bt[i] -= bedrag;
    • Else // Laatste cyclus voor dit proces
      • t = t + rem_bt[i];
      • wt[i] = t – bt[i]
      • rem_bt[i] = 0; // Dit proces is voorbij

Zodra we wachttijden hebben, kunnen we de doorlooptijd tat[i] van een proces berekenen als de som van wacht- en burst-tijden, d.w.z. wt[i] + bt[i].
Hieronder vindt u de implementatie van bovenstaande stappen.

C++




restoperator van Python
// C++ program for implementation of RR scheduling> #include> using> namespace> std;> // Function to find the waiting time for all> // processes> void> findWaitingTime(>int> processes[],>int> n,> >int> bt[],>int> wt[],>int> quantum)> {> >// Make a copy of burst times bt[] to store remaining> >// burst times.> >int> rem_bt[n];> >for> (>int> i = 0 ; i rem_bt[i] = bt[i]; int t = 0; // Current time // Keep traversing processes in round robin manner // until all of them are not done. while (1) { bool done = true; // Traverse all processes one by one repeatedly for (int i = 0 ; i { // If burst time of a process is greater than 0 // then only need to process further if (rem_bt[i]>0) { gedaan = onwaar; // Er is een proces in behandeling if (rem_bt[i]> quantum) {// Verhoog de waarde van t, d.w.z. laat zien // hoeveel tijd een proces is verwerkt t += quantum; // Verlaag de burst_time van het huidige proces // by quantum rem_bt[i] -= quantum; } // Als de burst-tijd kleiner is dan of gelijk is aan // quantum. Laatste cyclus voor dit proces else {// Verhoog de waarde van t, d.w.z. laat zien // hoeveel tijd een proces is verwerkt t = t + rem_bt[i]; // Wachttijd is de huidige tijd minus de tijd // gebruikt door dit proces wt[i] = t - bt[i]; // Terwijl het proces volledig wordt uitgevoerd // maak de resterende burst-tijd = 0 rem_bt[i] = 0; } } } // Als alle processen klaar zijn als (done == true) break; } } // Functie om de doorlooptijd te berekenen void findTurnAroundTime(int process[], int n, int bt[], int wt[], int tat[]) {// doorlooptijd berekenen door // bt[i] toe te voegen + wt[i] for (int i = 0; i tat[i] = bt[i] + wt[i]; } // Functie voor het berekenen van de gemiddelde tijd void findavgTime(int processen[], int n, int bt[ ], int quantum) { int wt[n], tat[n], total_wt = 0, total_tat = 0; // Functie om de wachttijd van alle processen te vinden findWaitingTime(processen, n, bt, wt, quantum); Functie om de doorlooptijd voor alle processen te vinden findTurnAroundTime(processes, n, bt, wt, tat // Geef processen weer samen met alle details cout<< 'PN '<< ' BT ' << ' WT ' << ' TAT '; // Calculate total waiting time and total turn // around time for (int i=0; i { total_wt = total_wt + wt[i]; total_tat = total_tat + tat[i]; cout << ' ' << i+1 << ' ' << bt[i] <<' ' << wt[i] <<' ' << tat[i] < } cout << 'Average waiting time = ' << (float)total_wt / (float)n; cout << ' Average turn around time = ' << (float)total_tat / (float)n; } // Driver code int main() { // process id's int processes[] = { 1, 2, 3}; int n = sizeof processes / sizeof processes[0]; // Burst time of all processes int burst_time[] = {10, 5, 8}; // Time quantum int quantum = 2; findavgTime(processes, n, burst_time, quantum); return 0; }>

>

>

Java




// Java program for implementation of RR scheduling> public> class> GFG> {> >// Method to find the waiting time for all> >// processes> >static> void> findWaitingTime(>int> processes[],>int> n,> >int> bt[],>int> wt[],>int> quantum)> >{> >// Make a copy of burst times bt[] to store remaining> >// burst times.> >int> rem_bt[] =>new> int>[n];> >for> (>int> i =>0> ; i rem_bt[i] = bt[i]; int t = 0; // Current time // Keep traversing processes in round robin manner // until all of them are not done. while(true) { boolean done = true; // Traverse all processes one by one repeatedly for (int i = 0 ; i { // If burst time of a process is greater than 0 // then only need to process further if (rem_bt[i]>0) { gedaan = onwaar; // Er is een proces in behandeling if (rem_bt[i]> quantum) {// Verhoog de waarde van t, d.w.z. laat zien // hoeveel tijd een proces is verwerkt t += quantum; // Verlaag de burst_time van het huidige proces // by quantum rem_bt[i] -= quantum; } // Als de burst-tijd kleiner is dan of gelijk is aan // quantum. Laatste cyclus voor dit proces else {// Verhoog de waarde van t, d.w.z. laat zien // hoeveel tijd een proces is verwerkt t = t + rem_bt[i]; // Wachttijd is de huidige tijd minus de tijd // gebruikt door dit proces wt[i] = t - bt[i]; // Terwijl het proces volledig wordt uitgevoerd // maak de resterende burst-tijd = 0 rem_bt[i] = 0; } } } // Als alle processen klaar zijn als (done == true) break; } } // Methode om de doorlooptijd te berekenen static void findTurnAroundTime(int process[], int n, int bt[], int wt[], int tat[]) {// doorlooptijd berekenen door // bt[i toe te voegen ] + wt[i] for (int i = 0; i tat[i] = bt[i] + wt[i]; } // Methode voor het berekenen van de gemiddelde tijd static void findavgTime(int processen[], int n, int bt[], int quantum) { int wt[] = new int[n], tat[] = new int[n]; int total_wt = 0, total_tat = 0 // Functie om de wachttijd van alle processen findWaitingTime( te vinden) processen, n, bt, wt, quantum); // Functie om de doorlooptijd voor alle processen te vinden findTurnAroundTime (processen, n, bt, wt, tat // Geef processen weer samen met alle details System.out.println ( 'PN ' + ' B ' + ' WT ' + ' TAT' // Bereken de totale wachttijd en totale draaitijd // rondtijd voor (int i=0; i { total_wt = total_wt +); wt[i]; totaal_tat = totaal_tat + tat[i]; Systeem.out.println(' ' + (i+1) + ' ' + bt[i] +' ' + wt[i] +' ' + tat[i] } System.out.println('Gemiddelde wachttijd = ' + (float)total_wt / (float)n); System.out.println('Gemiddelde doorlooptijd = ' + (float)total_tat / (float)n); } // Stuurprogrammamethode public static void main(String[] args) { // proces-id's int processen[] = { 1, 2, 3}; int n = processen.lengte; // Bursttijd van alle processen int burst_time[] = {10, 5, 8}; // Tijd kwantum int kwantum = 2; findavgTime(processen, n, burst_time, kwantum); } }>

>

>

Python3




# Python3 program for implementation of> # RR scheduling> # Function to find the waiting time> # for all processes> def> findWaitingTime(processes, n, bt,> >wt, quantum):> >rem_bt>=> [>0>]>*> n> ># Copy the burst time into rt[]> >for> i>in> range>(n):> >rem_bt[i]>=> bt[i]> >t>=> 0> # Current time> ># Keep traversing processes in round> ># robin manner until all of them are> ># not done.> >while>(>1>):> >done>=> True> ># Traverse all processes one by> ># one repeatedly> >for> i>in> range>(n):> > ># If burst time of a process is greater> ># than 0 then only need to process further> >if> (rem_bt[i]>>0>) :> >done>=> False> # There is a pending process> > >if> (rem_bt[i]>kwantum) :> > ># Increase the value of t i.e. shows> ># how much time a process has been processed> >t>+>=> quantum> ># Decrease the burst_time of current> ># process by quantum> >rem_bt[i]>->=> quantum> > ># If burst time is smaller than or equal> ># to quantum. Last cycle for this process> >else>:> > ># Increase the value of t i.e. shows> ># how much time a process has been processed> >t>=> t>+> rem_bt[i]> ># Waiting time is current time minus> ># time used by this process> >wt[i]>=> t>-> bt[i]> ># As the process gets fully executed> ># make its remaining burst time = 0> >rem_bt[i]>=> 0> > ># If all processes are done> >if> (done>=>=> True>):> >break> > # Function to calculate turn around time> def> findTurnAroundTime(processes, n, bt, wt, tat):> > ># Calculating turnaround time> >for> i>in> range>(n):> >tat[i]>=> bt[i]>+> wt[i]> # Function to calculate average waiting> # and turn-around times.> def> findavgTime(processes, n, bt, quantum):> >wt>=> [>0>]>*> n> >tat>=> [>0>]>*> n> ># Function to find waiting time> ># of all processes> >findWaitingTime(processes, n, bt,> >wt, quantum)> ># Function to find turn around time> ># for all processes> >findTurnAroundTime(processes, n, bt,> >wt, tat)> ># Display processes along with all details> >print>(>'Processes Burst Time Waiting'>,> >'Time Turn-Around Time'>)> >total_wt>=> 0> >total_tat>=> 0> >for> i>in> range>(n):> >total_wt>=> total_wt>+> wt[i]> >total_tat>=> total_tat>+> tat[i]> >print>(>' '>, i>+> 1>,>' '>, bt[i],> >' '>, wt[i],>' '>, tat[i])> >print>(>' Average waiting time = %.5f '>%>(total_wt>/>n) )> >print>(>'Average turn around time = %.5f '>%> (total_tat>/> n))> > # Driver code> if> __name__>=>=>'__main__'>:> > ># Process id's> >proc>=> [>1>,>2>,>3>]> >n>=> 3> ># Burst time of all processes> >burst_time>=> [>10>,>5>,>8>]> ># Time quantum> >quantum>=> 2>;> >findavgTime(proc, n, burst_time, quantum)> # This code is contributed by> # Shubham Singh(SHUBHAMSINGH10)>

>

>

C#

download youtube-video vlc




// C# program for implementation of RR> // scheduling> using> System;> public> class> GFG {> > >// Method to find the waiting time> >// for all processes> >static> void> findWaitingTime(>int> []processes,> >int> n,>int> []bt,>int> []wt,>int> quantum)> >{> > >// Make a copy of burst times bt[] to> >// store remaining burst times.> >int> []rem_bt =>new> int>[n];> > >for> (>int> i = 0 ; i rem_bt[i] = bt[i]; int t = 0; // Current time // Keep traversing processes in round // robin manner until all of them are // not done. while(true) { bool done = true; // Traverse all processes one by // one repeatedly for (int i = 0 ; i { // If burst time of a process // is greater than 0 then only // need to process further if (rem_bt[i]>0) {// Er is een proces in behandeling = false; if (rem_bt[i]> quantum) {// Verhoog de waarde van t, d.w.z. // laat zien hoeveel tijd een proces // is verwerkt t += quantum; // Verlaag de burst_time van // het huidige proces met quantum rem_bt[i] -= quantum; } // Als de burst-tijd kleiner is dan // of gelijk is aan quantum. Laatste cyclus // voor dit proces else {// Verhoog de waarde van t, d.w.z. // laat zien hoeveel tijd een proces // is verwerkt t = t + rem_bt[i]; // Wachttijd is actueel // tijd minus tijd gebruikt door // dit proces wt[i] = t - bt[i]; // Als het proces volledig wordt uitgevoerd // uitgevoerd, maak dan de resterende // burst-tijd = 0 rem_bt[i] = 0; } } } // Als alle processen klaar zijn als (done == true) break; } } // Methode om de doorlooptijd te berekenen static void findTurnAroundTime(int []processes, int n, int []bt, int []wt, int []tat) {// doorlooptijd berekenen door // bt[i toe te voegen ] + wt[i] for (int i = 0; i tat[i] = bt[i] + wt[i]; } // Methode voor het berekenen van de gemiddelde tijd static void findavgTime(int []processes, int n, int []bt, int quantum) { int []wt = new int[n]; int []tat = new int[n]; processen findWaitingTime(processen, n, bt, wt, quantum); // Functie om de doorlooptijd te vinden // voor alle processen findTurnAroundTime (processen, n, bt, wt, tat // Geef processen weer samen met // alle details Console.WriteLine('Processen ' + ' Bursttijd ' + ' Wachttijd ' + ' Doorlooptijd' // Bereken de totale wachttijd en de totale draaitijd // rondtijd voor (int i = 0; ik { totaal_wt = totaal_wt + wt[i]; totaal_tat + tat[i]; ] + ' ' + wt[i] +' ' + tat[i]); } Console.WriteLine('Gemiddelde wachttijd = ' + (float)total_wt / (float)n); Console.Write('Gemiddelde doorlooptijd = ' + (float)total_tat / (float)n); } // Stuurprogrammamethode public static void Main() {// process id's int []processes = { 1, 2, 3}; int n = processen.Lengte; // Bursttijd van alle processen int []burst_time = {10, 5, 8}; // Tijd kwantum int kwantum = 2; findavgTime(processen, n, burst_time, kwantum); } } // Deze code is bijgedragen door nitin mittal.>

>

>

Javascript


Java-object voor json



> >// JavaScript program for implementation of RR scheduling> >// Function to find the waiting time for all> >// processes> >const findWaitingTime = (processes, n, bt, wt, quantum) =>{> >// Make a copy of burst times bt[] to store remaining> >// burst times.> >let rem_bt =>new> Array(n).fill(0);> >for> (let i = 0; i rem_bt[i] = bt[i]; let t = 0; // Current time // Keep traversing processes in round robin manner // until all of them are not done. while (1) { let done = true; // Traverse all processes one by one repeatedly for (let i = 0; i // If burst time of a process is greater than 0 // then only need to process further if (rem_bt[i]>0) { gedaan = onwaar; // Er is een proces in behandeling if (rem_bt[i]> quantum) {// Verhoog de waarde van t, d.w.z. laat zien // hoeveel tijd een proces is verwerkt t += quantum; // Verlaag de burst_time van het huidige proces // by quantum rem_bt[i] -= quantum; } // Als de burst-tijd kleiner is dan of gelijk is aan // quantum. Laatste cyclus voor dit proces else {// Verhoog de waarde van t, d.w.z. laat zien // hoeveel tijd een proces is verwerkt t = t + rem_bt[i]; // Wachttijd is de huidige tijd minus de tijd // gebruikt door dit proces wt[i] = t - bt[i]; // Terwijl het proces volledig wordt uitgevoerd // maak de resterende burst-tijd = 0 rem_bt[i] = 0; } } } // Als alle processen klaar zijn als (done == true) break; } } // Functie om de doorlooptijd te berekenen const findTurnAroundTime = (processen, n, bt, wt, tat) => { // doorlooptijd berekenen door // bt[i] + wt[i] voor (let i = 0; i tat[i] = bt[i] + wt[i] } // Functie om de gemiddelde tijd te berekenen const findavgTime = (processen, n, bt, quantum) => {let wt = new Array(n). fill(0), tat = new Array(n).fill(0); let total_wt = 0, total_tat = 0; // Functie om de wachttijd van alle processen te vinden findWaitingTime(processen, n, bt, wt, quantum); // Functie om de doorlooptijd voor alle processen te vinden findTurnAroundTime(processes, n, bt, wt, tat); Geef processen weer samen met alle details document.write(`Processen Burst time Wachttijd Turn around time `); Bereken de totale wachttijd en de totale omlooptijd // rond tijd voor (laat i = 0; i total_wt = total_wt + wt[i]; total_tat = total_tat + tat[i]; document.write(`${i + 1} ${ bt[i]} ${wt[i]} ${tat[i]} `); document.write(`Gemiddelde wachttijd = ${total_wt / n}`); = ${totaal_tat / n}`); } // Stuurprogrammacode // proces-ID's processen = [1, 2, 3]; laat n = processen.lengte; // Bursttijd van alle processen laat burst_time = [10, 5, 8]; // Tijdkwantum laat kwantum = 2; findavgTime(processen, n, burst_time, kwantum); // Deze code is bijgedragen door rakeshsahni>

>

>

Uitvoer

PN BT WT TAT 1 10 13 23 2 5 10 15 3 8 13 21 Average waiting time = 12 Average turn around time = 19.6667>

Programma voor Round Robin-planning met aankomsttijd nul, verschillende en dezelfde aankomsttijden

C++




een object in Java

#include> #include> using> namespace> std;> struct> Process {> >int> AT, BT, ST[20], WT, FT, TAT, pos;> };> int> quant;> int> main() {> >int> n, i, j;> >// Taking Input> >cout <<>'Enter the no. of processes: '>;> >cin>> n;> >Process p[n];> >cout <<>'Enter the quantum: '> << endl;> >cin>> kwantitatief;> >cout <<>'Enter the process numbers: '> << endl;> >for> (i = 0; i cin>> p[i].pos; uit<< 'Enter the Arrival time of processes: ' << endl; for (i = 0; i cin>> p[i].AT; uit<< 'Enter the Burst time of processes: ' << endl; for (i = 0; i cin>> p[i].BT; // Variabelen declareren int c = n, s[n][20]; zweeftijd = 0, mini = INT_MAX, b[n], a[n]; // Initialisatie van burst- en aankomsttijdarrays int index = -1; voor (i = 0; ik b[i] = p[i].BT; a[i] = p[i].AT; voor (j = 0; j<20; j++) { s[i][j] = -1; } } int tot_wt, tot_tat; tot_wt = 0; tot_tat = 0; bool flag = false; while (c != 0) { mini = INT_MAX; flag = false; for (i = 0; i float p = time + 0.1; if (a[i] <= p && mini>a[i] && b[i]> 0) { index = i; mini = een[ik]; vlag = waar; } } // als op =1 dan komt de lus eruit, dus zet de vlag op false if (!flag) { time++; doorgaan; } // starttijd berekenen j = 0; terwijl (s[index][j] != -1) { j++; } als (s[index][j] == -1) { s[index][j] = tijd; p[index].ST[j] = tijd; } als (b[index]<= quant) { time += b[index]; b[index] = 0; } else { time += quant; b[index] -= quant; } if (b[index]>0) { a[index] = tijd + 0,1; } // aankomst, burst, eindtijden berekenen if (b[index] == 0) { c--; p[index].FT = tijd; p[index].WT = p[index].FT - p[index].AT - p[index].BT; tot_wt += p[index].WT; p[index].TAT = p[index].BT + p[index].WT; tot_tat += p[index].TAT; } } // einde van while-lus // Afdrukuitvoer cout<< 'Process number '; cout << 'Arrival time '; cout << 'Burst time '; cout << ' Start time'; j = 0; while (j != 10) { j += 1; cout << ' '; } cout << ' Final time'; cout << ' Wait Time '; cout << ' TurnAround Time' << endl; for (i = 0; i cout << p[i].pos << ' '; cout << p[i].AT << ' '; cout << p[i].BT << ' '; j = 0; int v = 0; while (s[i][j] != -1) { cout << p[i].ST[j] << ' '; j++; v += 3; } while (v != 40) { cout << ' '; v += 1; } cout << p[i].FT << ' '; cout << p[i].WT << ' '; cout << p[i].TAT << endl; } // Calculating average wait time and turnaround time double avg_wt, avg_tat; avg_wt = tot_wt / static_cast(N); avg_tat = tot_tat / statische_cast(N); // Gemiddelde wachttijd en doorlooptijd afdrukken<< 'The average wait time is: ' << avg_wt << endl; cout << 'The average TurnAround time is: ' << avg_tat << endl; return 0; }>

>

>

C




#include> #include> #include> struct> P{> int> AT,BT,ST[20],WT,FT,TAT,pos;> };> int> quant;> int> main(){> int> n,i,j;> // Taking Input> printf>(>'Enter the no. of processes :'>);> scanf>(>'%d'>,&n);> struct> P p[n];> > printf>(>'Enter the quantum '>);> scanf>(>'%d'>,&quant);> printf>(>'Enter the process numbers '>);> for>(i=0;i scanf('%d',&(p[i].pos)); printf('Enter the Arrival time of processes '); for(i=0;i scanf('%d',&(p[i].AT)); printf('Enter the Burst time of processes '); for(i=0;i scanf('%d',&(p[i].BT)); // Declaring variables int c=n,s[n][20]; float time=0,mini=INT_MAX,b[n],a[n]; // Initializing burst and arrival time arrays int index=-1; for(i=0;i b[i]=p[i].BT; a[i]=p[i].AT; for(j=0;j<20;j++){ s[i][j]=-1; } } int tot_wt,tot_tat; tot_wt=0; tot_tat=0; bool flag=false; while(c!=0){ mini=INT_MAX; flag=false; for(i=0;i float p=time+0.1; if(a[i]a[i] && b[i]>0){index=i; mini=a[i]; vlag=waar; } } // als op =1 dan komt de lus eruit, dus zet de vlag op false if(!flag){ time++; doorgaan; } //starttijd j=0 berekenen; terwijl(s[index][j]!=-1){ j++; } if(s[index][j]==-1){ s[index][j]=tijd; p[index].ST[j]=tijd; } als(b[index]<=quant){ time+=b[index]; b[index]=0; } else{ time+=quant; b[index]-=quant; } if(b[index]>0){ a[index]=tijd+0,1; } // aankomst, burst, eindtijden berekenen if(b[index]==0){ c--; p[index].FT=tijd; p[index].WT=p[index].FT-p[index].AT-p[index].BT; tot_wt+=p[index].WT; p[index].TAT=p[index].BT+p[index].WT; tot_tat+=p[index].TAT; } } // einde van while-lus // Afdrukuitvoer printf('Procesnummer '); printf('Aankomsttijd'); printf('Bursttijd'); printf(' Starttijd'); j=0; terwijl(j!=10){ j+=1; printf(''); } printf(' Eindtijd'); printf(' Wachttijd '); printf(' Doorlooptijd '); for(i=0;i printf('%d ',p[i].pos); printf('%d ',p[i].AT); printf ('%d ',p[i].BT); j=0; terwijl(s[i][j]!=-1){ printf('%d ' ,p[i].ST[j]); j++; v+=3; } terwijl(v!=40){ v+=1; ',p[i].FT);printf('%d ',p[i].WT); } //Berekende gemiddelde wachttijd en doorlooptijd dubbel avg_wt,avg_tat; avg_wt=tot_wt/(float)n; tijd is: %lf ',avg_wt); printf('De gemiddelde doorlooptijd is: %lf ',avg_tat);

> 

Enter the number of processes : 4 Enter the time quanta : 2 Enter the process numbers : 1 2 3 4 Enter the arrival time of the processes : 0 1 2 3 Enter the burst time of the processes : 5 4 2 1 Program No. Arrival Time Burst Time Wait Time TurnAround Time 1 0 5 7 12 2 1 4 6 10 3 2 2 2 4 4 3 1 5 6 Average wait time : 5 Average Turn Around Time : 8>

Programma voor Round Robin-planning met verschillende aankomsttijden voor alle processen

Voor een gedetailleerde implementatie van het Preemptive Round Robin-algoritme met verschillende aankomsttijden voor alle processen, raadpleegt u: Programma voor Round Robin Scheduling met verschillende aankomsttijden .

Conclusie

Kortom, Round Robin CPU-planning is een eerlijk en preventief algoritme dat een vast tijdkwantum aan elk proces toewijst, waardoor gelijke CPU-toegang wordt gegarandeerd. Het is eenvoudig te implementeren, maar kan leiden tot hogere overhead bij het wisselen van context. Hoewel het eerlijkheid bevordert en hongersnood voorkomt, kan het resulteren in langere wachttijden en een verminderde doorvoer, afhankelijk van het tijdskwantum. Effectieve programma-implementatie maakt de berekening mogelijk van belangrijke meetgegevens zoals doorlooptijd, doorlooptijd en wachttijd, wat helpt bij prestatie-evaluatie en optimalisatie.