O'zbekiston respublikasi raqamli texnologiyalar vazirligi muhammad al-Xorazmiy nomidagi Toshkent Axborot Texnologiyalari Universiteti




Download 69,43 Kb.
bet2/2
Sana06.06.2024
Hajmi69,43 Kb.
#260929
1   2
Bog'liq
Operatsion tizimlar mustaqil ish

10-momentda: P4 va P5 ni qolgan bajarilish vaqtlari kirib keladi. P4 ni burst time=6 sekund, P5 ni burst time=10 sekund. P4 ni burst time kichik bo’lgani sabab P4 6 sekund bajariladi.
- Vaqt oralig'i: 10-16
- Amalga oshiriladigan ish: P4


16-momentda: P5 ni burst time=10 sekund. P5 10 sekund bajariladi.
- Vaqt oralig'i: 16-26
- Amalga oshiriladigan ish: P5
Bunday holda, protsessor ishlash ketma-ketligini quyidagi tarzda bajargan bo'ladi:
1. P5 (0-2)
2. P4 (2-3)
3. P3 (3-5)
4. P1 (5-8)
5. P2 (8-10)
6. P4 (10-16)
7. P5 (16-26)
2. Round Robin Algoritmi yordamida o’rtacha kutish vaqtini topish.
Tartib raqamim: 29
Quantum Time (TQ) quyidagi formula yordamida hisoblanadi:

(29/3) + 2 = 7


Shunday qilib, quantum time 7 bo'ladi.


Keling, Round algoritmi yordamida protsessor ishlarini rejalashtirishni bajaramiz va o'rtacha kutish vaqtini topamiz. Berilgan protsessor ishlari quyidagicha:


- Process ID: P1, P2, P3, P4, P5


- Arrival time: 5, 6, 3, 2, 0
- Burst time: 3, 2, 2, 7, 12


Java dasturlash tilida Round Robin algoritmi yordamida protsessor ishlash ketma-ketligini rejalashtirish va o'rtacha kutish vaqtini hisoblash dasturini yozamiz.

import java.util.LinkedList;


import java.util.Queue;

class Process {


String pid;
int arrivalTime;
int burstTime;
int remainingTime;
int waitingTime;
int turnaroundTime;

Process(String pid, int arrivalTime, int burstTime) {


this.pid = pid;
this.arrivalTime = arrivalTime;
this.burstTime = burstTime;
this.remainingTime = burstTime;
this.waitingTime = 0;
this.turnaroundTime = 0;
}
}

public class RoundRobinScheduler {


public static void main(String[] args) {
Process[] processes = {
new Process("P1", 5, 3),
new Process("P2", 6, 2),
new Process("P3", 3, 2),
new Process("P4", 2, 7),
new Process("P5", 0, 12)
};

int quantum = 7; // Based on the given example


calculateAverageWaitingTime(processes, quantum);
}

public static void calculateAverageWaitingTime(Process[] processes, int quantum) {


Queue
queue = new LinkedList<>();
int currentTime = 0;
int totalWaitingTime = 0;
int totalTurnaroundTime = 0;
int completedProcesses = 0;

while (completedProcesses < processes.length) {


for (Process process : processes) {
if (process.arrivalTime <= currentTime && process.remainingTime > 0 && !queue.contains(process)) {
queue.add(process);
}
}

if (!queue.isEmpty()) {


Process currentProcess = queue.poll();
int timeSpent = Math.min(quantum, currentProcess.remainingTime);
currentProcess.remainingTime -= timeSpent;
currentTime += timeSpent;

for (Process process : processes) {


if (process != currentProcess && process.remainingTime > 0 && process.arrivalTime <= currentTime) {
process.waitingTime += timeSpent;
}
}

if (currentProcess.remainingTime > 0) {


queue.add(currentProcess);
} else {
currentProcess.turnaroundTime = currentTime - currentProcess.arrivalTime;
totalWaitingTime += currentProcess.waitingTime;
totalTurnaroundTime += currentProcess.turnaroundTime;
completedProcesses++;
}
} else {
currentTime++;
}
}

double averageWaitingTime = (double) totalWaitingTime / processes.length;


double averageTurnaroundTime = (double) totalTurnaroundTime / processes.length;

System.out.printf("Average Waiting Time: %.2f\n", averageWaitingTime);


System.out.printf("Average Turnaround Time: %.2f\n", averageTurnaroundTime);

for (Process process : processes) {


System.out.printf("%s -> Waiting Time: %d, Turnaround Time: %d\n",
process.pid, process.waitingTime, process.turnaroundTime);
}
}
}

Output:




Download 69,43 Kb.
1   2




Download 69,43 Kb.

Bosh sahifa
Aloqalar

    Bosh sahifa



O'zbekiston respublikasi raqamli texnologiyalar vazirligi muhammad al-Xorazmiy nomidagi Toshkent Axborot Texnologiyalari Universiteti

Download 69,43 Kb.