26 variant Guruh: 312-20 dif Bajardi: Shavkatov Behruz


Download 178.9 Kb.
Sana16.08.2023
Hajmi178.9 Kb.
#1667449
Bog'liq
Operatsion 2 Mustaqil





Muhammad Al-Xorazmiy nomidagi

Toshkent Axborot Texnologiyalari Universiteti

Operatsion tizimlar fanidan





MUSTAQIL ISH 2


Mavzu: Short Job First algoritmining(Non-Preemptive) bo’yicha o’rtacha
kutish vaqtini topish va ixtiyoriy dasturlash tilida dasturini tuzish talab qilinadi.
26 variant

Guruh: 312-20 dif
Bajardi: Shavkatov Behruz

Short Job First algoritmining(Non-Preemptive) bo’yicha o’rtacha


kutish vaqtini toping
Process ID Arrival time Burst time
P1 0 60
P2 3 30
P3 4 40
P4 9 10

Tartiblangan jarayonlar bo'yicha o'rtacha kutish vaqti toping.
P1: 0
P2: 60 (P1ning burst vaqti)
P3: 90 (P1 va P2ning burst vaqtini qo'shib)
P4: 130 (P1, P2 va P3ning burst vaqtini qo'shib)

3. O'rtacha kutish vaqti: (0 + 60 + 90 + 130) / 4 = 70.
import java.util.*;

class Process {


String id;
int arrivalTime;
int burstTime;

public Process(String id, int arrivalTime, int burstTime) {


this.id = id;
this.arrivalTime = arrivalTime;
this.burstTime = burstTime;
}
}

class SJF {


public static void main(String[] args) {
List
processes = new ArrayList<>();
processes.add(new Process("P1", 0, 60));
processes.add(new Process("P2", 3, 30));
processes.add(new Process("P3", 4, 40));
processes.add(new Process("P4", 9, 10));

// Jarayonlarni kelish vaqtiga qarab tartiblash


Collections.sort(processes, Comparator.comparingInt(p -> p.arrivalTime));

int n = processes.size();


int[] waitingTime = new int[n];
int[] turnaroundTime = new int[n];

// Har bir jarayon uchun kutish va qayta ishlash vaqtini hisoblash


waitingTime[0] = 0;
for (int i = 1; i < n; i++) {
Process currentProcess = processes.get(i);
int prevBurstTime = processes.get(i - 1).burstTime;
waitingTime[i] = prevBurstTime + waitingTime[i - 1];
}

// Calculate turnaround time


for (int i = 0; i < n; i++) {
turnaroundTime[i] = processes.get(i).burstTime + waitingTime[i];
}

// Calculate average waiting time and average turnaround time


int totalWaitingTime = 0;
int totalTurnaroundTime = 0;
for (int i = 0; i < n; i++) {
totalWaitingTime += waitingTime[i];
totalTurnaroundTime += turnaroundTime[i];
}
double averageWaitingTime = (double) totalWaitingTime / n;
double averageTurnaroundTime = (double) totalTurnaroundTime / n;

// Print the results


System.out.println("Process\tArrival Time\tBurst Time\tWaiting Time\tTurnaround Time");
for (int i = 0; i < n; i++) {
Process process = processes.get(i);
System.out.printf("%s\t\t%d\t\t%d\t\t%d\t\t%d\n", process.id, process.arrivalTime, process.burstTime,
waitingTime[i], turnaroundTime[i]);
}
System.out.println("\nAverage Waiting Time: " + averageWaitingTime);
System.out.println("Average Turnaround Time: " + averageTurnaroundTime);
}
}

Va screenshot dastur ishlagani haqida
2-topshiriq:Round Robin Algoritmi yordamida o’rtacha kutish vaqtini topish
va ixtiyoriy dasturlash tilida dasturini tuzish talab qilinadi
import java.util.*;

class RoundRobin {


public static void main(String[] args) {
Scanner input = new Scanner(System.in);

System.out.print("Ishchi sonini kiriting: ");


int ishchiSon = input.nextInt();

int[] ishVaqt = new int[ishchiSon];

System.out.println("Har bir ishchi uchun ish vaqtlarini kiriting:");
for (int i = 0; i < ishchiSon; i++) {
System.out.print("Ish vaqti #" + (i + 1) + ": ");
ishVaqt[i] = input.nextInt();
}

System.out.print("Zaman dilimini kiriting: ");


int zamanDilimi = input.nextInt();

input.close();

int[] beklemeVaqt = new int[ishchiSon];
int toplamBeklemeVaqt = 0;

// Round Robin algoritmasini qo'llash


while (true) {
boolean ishlarTugadi = true;

for (int i = 0; i < ishchiSon; i++) {


if (ishVaqt[i] > 0) {
ishlarTugadi = false;

if (ishVaqt[i] <= zamanDilimi) {


// Ish vaqti zaman dilimidan kichik yoki teng bo'lsa
toplamBeklemeVaqt += ishVaqt[i];
ishVaqt[i] = 0;
} else {
// Ish vaqti zaman dilimidan katta bo'lsa
toplamBeklemeVaqt += zamanDilimi;
ishVaqt[i] -= zamanDilimi;
}
}
}

if (ishlarTugadi)


break;
}

double ortachaKutishVaqt = (double) toplamBeklemeVaqt / ishchiSon;


System.out.println("Ortacha kutish vaqti: " + ortachaKutishVaqt);
}
}
Download 178.9 Kb.

Do'stlaringiz bilan baham:




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling