Content-Length: 3131808 | pFad | https://www.scribd.com/document/724197905/CC-2-1
9Computer Science &: Department of
Computer Science &: Department of
Computer Science &: Department of
Experiment 2.1
Student Name: Somya Kukreti UID:21BCS3656
Branch: BE-CSE Section/Group:21BCS_CC_610_B
Date of Performance: 27-02-2024 Semester: 6th
Subject Name: Cloud Computing & Distributed Systems
Lab Subject Code: 21CSP-378
1. Aim: Simulate a cloud scenario using Matlab and run a scheduling algorithm.
4. Procedure:
Step 1: Write down the java code for executing FCFS scheduling algorithms
import java.text.ParseException;
class GFG {
}
}
findavgTime(processes, n, burst_time);
}
}
Step 2: Write down the java code for executing SJF scheduling algorithms
DEPARTMENT OF
COMPUTER SCIENCE &
import java.io.*;
import java.util.*;
class Main {
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
int n;
// Matrix for storing Process Id, Burst
// Time, Average Waiting Time & Average
// Turn Around Time. int[]
[] A = new int[100][4]; int
total = 0;
float avg_wt, avg_tat;
System.out.println("Enter number of
process:"); n = input.nextInt();
System.out.println("Enter Burst Time:");
for (int i = 0; i < n; i++) {
// User Input Burst Time and alloting
// Process Id.
System.out.print("P" + (i + 1) + ": "); A[i]
[1] = input.nextInt();
A[i][0] = i + 1;
}
for (int i = 0; i < n; i++) {
// Sorting process according to their
// Burst Time.
int index = i;
for (int j = i + 1; j < n; j++) {
if (A[j][1] < A[index][1])
{index = j;
}
}
int temp = A[i][1];
A[i][1] = A[index]
[1]; A[index][1] =
temp; temp = A[i][0];
A[i][0] = A[index]
[0]; A[index][0] =
temp;
}
A[0][2] = 0;
// Calculation of Waiting Times
for (int i = 1; i < n; i++)
{A[i][2] = 0;
for (int j = 0; j < i; j++)
{A[i][2] += A[j][1];
}
total += A[i][2];
}
avg_wt = (float)total /
n; total = 0;
// Calculation of Turn Around Time and printing the
// data.
DEPARTMENT OF
COMPUTER SCIENCE &
System.out.println("P\tBT\tWT\tTAT");
for (int i = 0; i < n; i++)
{ A[i][3] = A[i][1]
+ A[i][2];
total += A[i][3];
System.out.println("P" + A[i][0] + "\
t"
+ A[i][1] + "\t" + A[i][2]
+ "\t" + A[i][3]);
}
avg_tat = (float)total / n;
System.out.println("Average Waiting Time= "
+ avg_wt);
System.out.println("Average Turnaround Time= "
+ avg_tat);
}
}
Step 3: Write down the java code for executing Round Robin scheduling algorithms
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 < n ; i+
+)
rem_bt[i] = bt[i];
// Driver Method
public static void main(String[] args)
{
// process id's
int processes[] = { 1, 2, 3};
int n = processes.length;
// Time quantum
int quantum = 2;
findavgTime(processes, n, burst_time, quantum);
}
}
5. Output:-
FCFS:
SJF:
DEPARTMENT OF
COMPUTER SCIENCE &
Round Robin:
6. Learning Outcome:
i). Learned how to install and use Eclipse IDE
ii). Learned how to install Cloud sim IDE and how to use
it with eclipse.
Fetched URL: https://www.scribd.com/document/724197905/CC-2-1
Alternative Proxies: