同じ到着時刻のラウンドロビンスケジュールのプログラム

同じ到着時刻のラウンドロビンスケジュールのプログラム

ラウンドロビン は、各プロセスに固定タイムスロットが周期的に割り当てられる CPU スケジューリング アルゴリズムです。これは、先着順 CPU スケジューリング アルゴリズムのプリエンプティブ バージョンです。

  • ラウンド ロビン CPU アルゴリズムは通常、タイム シェアリング技術に重点を置いています。
  • プロセスまたはジョブがプリエンプティブな方法で実行できる期間は、時間と呼ばれます。 量子
  • レディキューに存在する各プロセスまたはジョブには、その時間クォンタムの CPU が割り当てられます。その時間内にプロセスの実行が完了すると、プロセスは 終わり それ以外の場合、プロセスは元の状態に戻ります。 待機テーブル そして、次のターンが実行を完了するまで待ちます。

ラウンドロビン CPU スケジューリング アルゴリズムの特徴

  • シンプルで実装が簡単で、すべてのプロセスが CPU の公平なシェアを取得するため、飢餓が発生しません。
  • で最も一般的に使用されるテクニックの 1 つ CPU スケジューリング コアです。
  • それは 先制的な プロセスに CPU が割り当てられるのは、最大でも固定された時間スライスだけであるためです。
  • 欠点は、コンテキスト切り替えのオーバーヘッドが大きくなることです。

ラウンドロビン CPU スケジューリング アルゴリズムの利点

  • すべてのプロセスが均等に CPU を共有するため、公平性が保たれます。
  • 新しく作成されたプロセスは、準備完了キューの最後に追加されます。
  • ラウンドロビン スケジューラは通常、タイム シェアリングを採用し、各ジョブにタイム スロットまたはクォンタムを与えます。
  • ラウンドロビン スケジューリングの実行中、特定の時間量がさまざまなジョブに割り当てられます。
  • 各プロセスは、このスケジューリングで特定のクォンタムタイムの後に再スケジュールする機会を取得します。

ラウンドロビン CPU スケジューリング アルゴリズムの欠点

  • 待ち時間と応答時間が長くなります。
  • スループットが低い。
  • コンテキストスイッチがあります。
  • ガント チャートが大きすぎるように思えます (スケジューリングのクォンタム時間が短い場合。例: 大きなスケジューリングの場合は 1 ミリ秒)。
  • 少量の量子では時間のかかるスケジューリング。

動作を示す例 ラウンドロビン スケジュールアルゴリズム

例-1: 4 つのプロセスの到着時間とバースト時間を示す次の表を検討してください。 P1、P2、P3、P4 そして与えられた 時間量子 = 2

プロセス バーストタイム 到着時刻
P1 5ミリ秒 0ミリ秒
P2 4ミリ秒 1ミリ秒
P3 2ミリ秒 2ミリ秒
P4 1ミリ秒 4ミリ秒

ラウンド ロビン CPU スケジューリング アルゴリズムは、以下の手順に基づいて機能します。

時間 = 0 の場合、

  • 実行は、バースト時間 5 のプロセス P1 から始まります。
  • ここでは、すべてのプロセスが 2 ミリ秒間実行されます ( 時間量子周期 )。 P2 と P3 はまだ待機キューにあります。
時間インスタンス プロセス 到着時刻 レディキュー 実行中のキュー 実行時間 初期バースト時間 残りのバースト
時間
0~2ミリ秒 P1 0ミリ秒 P2、P3 P1 2ミリ秒 5ミリ秒 3ミリ秒

時間 = 2 のとき、

  • プロセス P1 と P3 が準備完了キューに到着し、P2 が実行を開始します。 TQ 期間
時間インスタンス プロセス 到着時刻 レディキュー 実行中のキュー 実行時間 初期バースト時間 残りのバースト
時間
2~4ミリ秒 P1 0ミリ秒 P3、P1 P2 0ミリ秒 3ミリ秒 3ミリ秒
P2 1ms 2ミリ秒 4ミリ秒 2ミリ秒

時間 = 4 のとき、

  • プロセス P4 が到着します。 準備完了キュー
  • 次に、P3 が実行されます。 TQ 期間。
時間インスタンス プロセス 到着時刻 レディキュー 実行中のキュー 実行時間 初期バースト時間 残りのバースト
時間
4~6ミリ秒 P1 0ミリ秒 P1、P4、P2 P3 0ミリ秒 3ミリ秒 3ミリ秒
P2 1ms 0ミリ秒 2ミリ秒 2ミリ秒
P3 2ミリ秒 2ミリ秒 2ミリ秒 0ミリ秒

時刻 = 6、

  • プロセス P3 が実行を完了する
  • プロセス P1 が実行を開始します TQ b の次のピリオドとなります。
時間インスタンス プロセス 到着時刻 レディキュー 実行中のキュー 実行時間 初期バースト時間 残りのバースト
時間
6~8ミリ秒 P1 0ミリ秒 P4、P2 P1 2ミリ秒 3ミリ秒 1ミリ秒
P2 1ms 0ミリ秒 2ミリ秒 2ミリ秒

時刻 = 8、

  • プロセス P4 の実行が開始されますが、しばらく実行されません。 時間量子周期 バースト時間 = 1 であるため
  • したがって、実行時間はわずか 1ms です。
時間インスタンス プロセス 到着時刻 レディキュー 実行中のキュー 実行時間 初期バースト時間 残りのバースト
時間
8~9ミリ秒 P1 0ミリ秒 P2、P1 P4 0ミリ秒 3ミリ秒 1ミリ秒
P2 1ms 0ミリ秒 2ミリ秒 2ミリ秒
P4 4ミリ秒 1ms 1ms 0ミリ秒

時刻 = 9、

  • プロセス P4 が実行を完了する
  • プロセス P2 が実行を開始します TQ 次の期間 準備完了キュー
時間インスタンス プロセス 到着時刻 レディキュー 実行中のキュー 実行時間 初期バースト時間 残りのバースト
時間
9~11ミリ秒 P1 0ミリ秒 P1 P2 0ミリ秒 3ミリ秒 1ms
P2 1ms 2ミリ秒 2ミリ秒 0ミリ秒

時刻 = 11、

  • プロセス P2 が実行を完了します。
  • プロセス P1 が実行を開始します。1ms だけ実行されます。
時間インスタンス プロセス 到着時刻 レディキュー 実行中のキュー 実行時間 初期バースト時間 残りのバースト
時間
11~12ミリ秒 P1 0ミリ秒 P1 1ms 1ms 0ミリ秒

時刻 = 12、

  • プロセス P1 が実行を完了します。
  • プロセスの全体的な実行は次のようになります。
時間インスタンス プロセス 到着時刻 レディキュー 実行中のキュー 実行時間 初期バースト時間 残りのバースト
時間
0~2ミリ秒 P1 0ミリ秒 P2、P3 P1 2ミリ秒 5ミリ秒 3ミリ秒
2~4ミリ秒 P1 0ミリ秒 P3、P1 P2 0ミリ秒 3ミリ秒 3ミリ秒
P2 1ms 2ミリ秒 4ミリ秒 2ミリ秒
4~6ミリ秒 P1 0ミリ秒 P1、P4、P2 P3 0ミリ秒 3ミリ秒 3ミリ秒
P2 1ms 0ミリ秒 2ミリ秒 2ミリ秒
P3 2ミリ秒 2ミリ秒 2ミリ秒 0ミリ秒
6~8ミリ秒 P1 0ミリ秒 P4、P2 P1 2ミリ秒 3ミリ秒 1ms
P2 1ms 0ミリ秒 2ミリ秒 2ミリ秒
8~9ミリ秒 P1 0ミリ秒 P2、P1 P4 0ミリ秒 3ミリ秒 1ms
P2 1ms 0ミリ秒 2ミリ秒 2ミリ秒
P4 4ミリ秒 1ms 1ms 0ミリ秒
9~11ミリ秒 P1 0ミリ秒 P1 P2 0ミリ秒 3ミリ秒 1ms
P2 1ms 2ミリ秒 2ミリ秒 0ミリ秒
11~12ミリ秒 P1 0ミリ秒 P1 1ms 1ms 0ミリ秒

ガントチャート は以下のようになります。

ラウンドロビンスケジューリングアルゴリズムのガントチャート

ラウンドロビンスケジューリングアルゴリズムのガントチャート

プログラムを使用してラウンドロビンで以下の時間を計算するにはどうすればよいですか?

  • 完了時間: プロセスの実行が完了した時刻。
  • ターンアラウンドタイム: 時間 完了時刻と到着時刻の差。 所要時間 = 完了時間 – 到着時間
  • 待ち時間(W.T): 時間 ターンアラウンドタイムとバーストタイムの差。
    待ち時間 = ターンアラウンドタイム – バーストタイム

では、平均値を計算してみましょう 待ち時間と折り返し 時間:

プロセス BT CT TAT WT
P1 0 5 12 12-0 = 12 12-5 = 7
P2 1 4 十一 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

今、

  • 平均所要時間 = (12 + 10 + 4 + 5)/4 = 31/4 = 7.7
  • 平均待ち時間 = (7 + 6 + 2 + 4)/4 = 19/4 = 4.7

例 2: 3 つのプロセス P1、P2、および P3 の到着時間とバースト時間の次の表を考えてみましょう。 時間量子 = 2

プロセス バーストタイム 到着時刻
P1 10ミリ秒 0ミリ秒
P2 5ミリ秒 0ミリ秒
P3 8ミリ秒 0ミリ秒

同様に、 ガントチャート この例の場合:

ガントチャート例2

ガントチャート例2

では、平均値を計算してみましょう 待ち時間と折り返し 時間:

プロセス BT CT TAT WT
P1 0 10 23 23-0 = 23 23-10 = 13
P2 0 5 15 15-0 = 15 15-5 = 10
P3 0 8 21 21-0 = 21 21-8 = 13

合計所要時間 = 59 ミリ秒
それで、 平均所要時間 = 59/3 = 19.667 ミリ秒

そして、合計待機時間 = 36 ミリ秒
それで、 平均待ち時間 = 36/3 = 12.00 ミリ秒

全工程の到着時間を0とするラウンドロビンスケジューリングのプログラム

全プロセスの待ち時間を求める手順

  • 配列を作成する レム_bt[] プロセスの残りのバースト時間を追跡します。この配列は最初は bt[] (バースト回数配列) のコピーです。
  • 別の配列を作成する 重量[] プロセスの待ち時間を保存します。この配列を 0 として初期化します。
  • 初期化時間: t = 0
  • すべてのプロセスが完了していない間は、すべてのプロセスを実行し続けます。次のことを実行します 私は まだ完了していない場合は処理します。
    • rem_bt[i]> 量子の場合
      • t = t + 量子
      • rem_bt[i] -= 金額;
    • Else // このプロセスの最後のサイクル
      • t = t + rem_bt[i];
      • wt[i] = t – bt[i]
      • rem_bt[i] = 0; // この処理は終了です

待機時間を取得したら、プロセスのターンアラウンドタイム tat[i] を待機時間とバースト時間の合計、つまり wt[i] + bt[i] として計算できます。
以下は上記の手順の実装です。

C++




// 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) { 完了 = false; // 保留中のプロセスがあります if (rem_bt[i]> quantum) { // t の値を増やします。つまり、 // プロセスが処理された時間を示します t += quantum; // 現在のプロセスのburst_timeを // quantumだけ減らす rem_bt[i] -= quantum; } // バースト時間が // quantum 以下の場合。このプロセスの最後のサイクル else { // t の値を増やします。つまり、 // プロセスが処理された時間を示します t = t + rem_bt[i]; // 待機時間は現在時刻から時間を引いたものです // このプロセスで使用される wt[i] = t - bt[i]; // プロセスが完全に実行されると、 // 残りのバースト時間 = 0 rem_bt[i] = 0; になります。 } } } // すべての処理が完了した場合 if (done == true) Break; } } // ターンアラウンドタイムを計算する関数 void findTurnAroundTime(int Processes[], int n, int bt[], int wt[], int tat[]) { // bt[i] を加算してターンアラウンドタイムを計算+ wt[i] for (int i = 0; i tat[i] = bt[i] + wt[i]; } // 平均時間を計算する関数 void findavgTime(intprocesses[], int n, int bt[ ], int quantum) { int wt[n], tat[n], total_wt = 0, total_tat = 0; // 全プロセスの待ち時間を求める関数 findWaitingTime(processes, n, bt, wt, quantum);すべてのプロセスのターンアラウンドタイムを見つける関数 findTurnAroundTime(processes, n, bt, wt, tat) // すべての詳細とともにプロセスを表示します 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 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) { 完了 = false; // 保留中のプロセスがあります if (rem_bt[i]> quantum) { // t の値を増やします。つまり、 // プロセスが処理された時間を示します t += quantum; // 現在のプロセスのburst_timeを // quantumだけ減らす rem_bt[i] -= quantum; } // バースト時間が // quantum 以下の場合。このプロセスの最後のサイクル else { // t の値を増やします。つまり、 // プロセスが処理された時間を示します t = t + rem_bt[i]; // 待機時間は現在時刻から時間を引いたものです // このプロセスで使用される wt[i] = t - bt[i]; // プロセスが完全に実行されると、 // 残りのバースト時間 = 0 rem_bt[i] = 0; になります。 } } } // すべての処理が完了した場合 if (done == true) Break; } } // ターンアラウンドタイムを計算するメソッド static void findTurnAroundTime(int Processes[], int n, int bt[], int wt[], int tat[]) { // bt[i を追加してターンアラウンドタイムを計算します] + wt[i] for (int i = 0; i tat[i] = bt[i] + wt[i]; } // 平均時間を計算するメソッド static void findavgTime(int Processes[], int n, int bt[], int quantum) { int wt[] = new int[n], tat[] = new int[n]; int total_wt = 0, total_tat = 0; // 全プロセスの待ち時間を求める関数 findWaitingTime( process, n, bt, wt, quantum); // すべてのプロセスのターンアラウンドタイムを見つける関数 findTurnAroundTime(processes, n, bt, wt, tat); // すべての詳細とともにプロセスを表示します。 'PN ' + ' B ' + ' WT ' + ' TAT') // 合計待機時間と合計ターン時間を計算します // (int i=0; i { total_wt = total_wt + wt[i]; total_tat = total_tat + tat[i]; System.out.println(' ' + (i+1) + ' ' + bt[i] +' ' + wt[i] +' ' + tat[i]); } System.out.println('平均待ち時間 = ' + (float)total_wt / (float)n); System.out.println('平均所要時間 = ' + (float)total_tat / (float)n); } // ドライバー メソッド public static void main(String[] args) { // プロセス ID の int Processes[] = { 1, 2, 3}; int n = プロセスの長さ; // 全プロセスのバースト時間 int burn_time[] = {10, 5, 8}; // タイムクォンタム int quantum = 2; findavgTime(プロセス、n、バースト時間、量子); } }>>

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]>量子) :>>' ,> > '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#




// 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) { // 保留中のプロセスが完了しました = false; if (rem_bt[i]> quantum) { // t の値を増やします。つまり、 // プロセスが処理された時間を示します。 // t += quantum; // 現在のプロセスのburst_timeを // 量子分だけ減らす rem_bt[i] -= quantum; } // バースト時間が // quantum より小さい場合。 // このプロセスの最後のサイクル else { // t の値を増やします。つまり、 // プロセスが処理された時間を示します。 // t = t + rem_bt[i]; // 待機時間は現在の時間です // 時間から // このプロセスで使用される時間を引いたものです wt[i] = t - bt[i]; // プロセスが完全に実行されると、 // 残りのバースト時間 = 0 rem_bt[i] = 0 になります。 } } } // すべての処理が完了した場合 if (done == true) Break; } } // ターンアラウンドタイムを計算するメソッド static void findTurnAroundTime(int []processes, int n, int []bt, int []wt, int []tat) { // ターンアラウンドタイムを計算するには // bt[i ] + wt[i] for (int i = 0; i tat[i] = bt[i] + wt[i]; } // 平均時間を計算するメソッド static void findavgTime(int []processes, int n, int []bt, int quantum) { int []wt = new int[n]; int []tat = new int[n]; int total_wt = 0, total_tat = 0; // すべての待ち時間を求める関数プロセス findWaitingTime(processes, n, bt, wt, quantum); // すべてのプロセスのターン アラウンド タイムを見つける関数 findTurnAroundTime(processes, n, bt, wt, tat) // すべての詳細を表示します。 Console.WriteLine('プロセス ' + ' バースト時間 ' + ' 待機時間 ' + ' ターンアラウンドタイム') // 合計待機時間と合計ターンアラウンドタイムを計算します // (int i) = 0; i { 合計_wt = 合計_wt + wt[i]; 合計_tat = 合計_tat + tat[i]; ] + ' ' + wt[i] +' ' + tat[i]); Console.WriteLine('平均待ち時間 = ' + (float)total_wt / (float)n); Console.Write('平均所要時間 = ' + (float)total_tat / (float)n); } // ドライバー メソッド public static void Main() { // プロセス ID の int []processes = { 1, 2, 3}; int n = プロセスの長さ; // 全プロセスのバースト時間 int []burst_time = {10, 5, 8}; // タイムクォンタム int quantum = 2; findavgTime(プロセス、n、バースト時間、量子); } } // このコードは nitin mittal によって寄稿されました。>>

JavaScript




> > // 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) { 完了 = false; // 保留中のプロセスがあります if (rem_bt[i]> quantum) { // t の値を増やします。つまり、 // プロセスが処理された時間を示します t += quantum; // 現在のプロセスのburst_timeを // quantumだけ減らす rem_bt[i] -= quantum; } // バースト時間が // quantum 以下の場合。このプロセスの最後のサイクル else { // t の値を増やします。つまり、 // プロセスが処理された時間を示します t = t + rem_bt[i]; // 待機時間は現在時刻から時間を引いたものです // このプロセスで使用される wt[i] = t - bt[i]; // プロセスが完全に実行されると、 // 残りのバースト時間 = 0 rem_bt[i] = 0; になります。 } } } // すべての処理が完了した場合 if (done == true) Break; } } // 所要時間を計算する関数 const findTurnAroundTime = (processes, n, bt, wt, tat) => { // bt[i] + wt[i] を加算して所要時間を計算 // (let i = 0; i tat[i] = bt[i] + wt[i]; } // 平均時間を計算する関数 const findavgTime = (processes, n, bt, quantum) => { let wt = new Array(n). fill(0), tat = new Array(n).fill(0); let total_wt = 0, total_tat = 0; // 全プロセスの待ち時間を求める関数 findWaitingTime(processes, n, bt, wt, quantum); // すべてのプロセスのターンアラウンドタイムを見つける関数 findTurnAroundTime(processes, n, bt, wt, tat); // すべての詳細とともにプロセスを表示 document.write(`Processes Burst time Waiting time Turn around time `);総待ち時間と総ターン時間を計算 // おおよその時間を (let 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(`平均待ち時間 = ${total_wt / n}`); = ${total_tat / n}`); } // ドライバー コード // プロセス ID のプロセス = [1, 2, 3]; n = プロセスの長さ; とします。 // すべてのプロセスのバースト時間 letburst_time = [10, 5, 8]; // タイムクォンタム let quantum = 2; findavgTime(プロセス、n、バースト時間、量子); // このコードは rakeshsahni によって寄稿されました>>

出力

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 

到着時刻をゼロ、異なる到着時刻および同じ到着時刻とするラウンドロビンスケジューリングのプログラム

C++




#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>> ん;>> > Process p[n];> > cout < <> 'Enter the quantum: '> < < endl;> > cin>> 量的;>> > cout < <> 'Enter the process numbers: '> < < endl;> > for> (i = 0; i cin>> p[i].pos; コート < < 'Enter the Arrival time of processes: ' < < endl; for (i = 0; i cin>> p[i].AT; コート < < 'Enter the Burst time of processes: ' < < endl; for (i = 0; i cin>> p[i].BT; // 変数の宣言 int c = n, s[n][20]; float 時間 = 0、mini = INT_MAX、b[n]、a[n]; // バースト配列と到着時刻配列を初期化します。 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] <= p && mini>a[i] && b[i]> 0) { インデックス = i; ミニ = a[i]; フラグ = true; } } // =1 の場合、ループが終了するため、フラグを false に設定します if (!flag) { time++; 続く; } // 開始時刻を計算します j = 0; while (s[インデックス][j] != -1) { j++; if (s[index][j] == -1) { s[index][j] = 時間; p[インデックス].ST[j] = 時間; if (b[インデックス] <= quant) { time += b[index]; b[index] = 0; } else { time += quant; b[index] -= quant; } if (b[index]>0) { a[インデックス] = 時間 + 0.1; } // 到着時間、バースト時間、最終時間を計算します if (b[index] == 0) { c--; p[インデックス].FT = 時間; p[インデックス].WT = p[インデックス].FT - p[インデックス].AT - p[インデックス].BT; tot_wt += p[インデックス].WT; p[インデックス].TAT = p[インデックス].BT + p[インデックス].WT; tot_tat += p[インデックス].TAT; } } // while ループの終わり // 出力 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 / static_cast (n); // 平均待ち時間と所要時間 cout を出力します < < '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){インデックス=i; ミニ=a[i]; フラグ = true; } } // =1 の場合、ループが終了するため、フラグを false に設定します。 if(!flag){ time++; 続く; } //開始時刻を計算 j=0; while(s[インデックス][j]!=-1){ j++; if(s[インデックス][j]==-1){ s[インデックス][j]=時間; p[インデックス].ST[j]=時間; if(b[インデックス] <=quant){ time+=b[index]; b[index]=0; } else{ time+=quant; b[index]-=quant; } if(b[index]>0){ a[インデックス]=時間+0.1; } // 到着時間、バースト時間、最終時間を計算します if(b[index]==0){ c--; p[インデックス].FT=時間; p[インデックス].WT=p[インデックス].FT-p[インデックス].AT-p[インデックス].BT; tot_wt+=p[インデックス].WT; p[インデックス].TAT=p[インデックス].BT+p[インデックス].WT; tot_tat+=p[インデックス].TAT; } } // while ループの終了 // 出力を印刷します printf('プロセス番号 '); printf('到着時刻'); printf('バースト時間'); printf(' 開始時刻'); j=0; while(j!=10){ j+=1; printf(' '); printf(' 最終時間'); printf(' 待機時間'); printf(' ターンアラウンドタイム ​​'); for(i=0;i printf('%d ',p[i].pos); printf('%d ',p[i].AT); printf ('%d ',p[i].BT); j=0; int v=0; while(s[i][j]!=-1){ printf('%d ' ,p[i].ST[j]); v+=3; } while(v!=40){ printf('%d ; ',p[i].FT); printf('%d ',p[i].WT); ; } //平均待ち時間と所要時間を計算します double avg_wt,avg_tat; avg_tat=tot_tat/(float)n; //平均待ち時間と所要時間を出力します。時間は : %lf ',avg_wt); printf('平均ターンアラウンド時間は : %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 

全工程の到着時刻が異なるラウンドロビンスケジューリングプログラム

すべてのプロセスの到着時間が異なるプリエンプティブ ラウンド ロビン アルゴリズムの詳細な実装については、以下を参照してください。 到着時刻が異なるラウンドロビンスケジュールのプログラム

結論

結論として、ラウンド ロビン CPU スケジューリングは、各プロセスに一定のタイム クォンタムを割り当て、均等な CPU アクセスを保証する、公平かつプリエンプティブなアルゴリズムです。実装は簡単ですが、コンテキスト切り替えのオーバーヘッドが高くなる可能性があります。これにより公平性が促進され、飢餓が防止されますが、時間量によっては待ち時間が長くなり、スループットが低下する可能性があります。効果的なプログラムの実装により、完了時間、所要時間、待機時間などの主要な指標を計算できるようになり、パフォーマンスの評価と最適化に役立ちます。